“文本”已弃用

Posted

技术标签:

【中文标题】“文本”已弃用【英文标题】:"text" is deprecated 【发布时间】:2014-07-17 18:39:43 【问题描述】:

我正准备将 ios 6 iPhone 应用程序更新到 iOS8。此代码的第二行产生一条错误消息(。在 iOS 3.0 中首次弃用)。语法错误多年来一直在我的应用程序中没有造成问题,但我认为我会在完成我的 iOS 8 版本之前清理所有错误。

- (void)tableView:(UITableView *)tv1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

    [appDelegate muniClicked:[[tableView cellForRowAtIndexPath:indexPath] text]];
    NSLog(@"cell clicked %d, %d", indexPath.row, indexPath.section);


【问题讨论】:

你的问题到底是什么? 您查看过UITableViewCell 的文档吗?自 iOS 3.0 起,text 属性已被弃用!文档告诉你用什么代替它。 【参考方案1】:

不要使用[[tableView cellForRowAtIndexPath:indexPath] text] 来获取UITableViewCell 中显示的文本,试试这个:

[[[tableView cellForRowAtIndexPath:indexPath] textLabel] text]

来自UITableViewCell documentation的参考。

根据您的单元格结构,查看detailTextLabel 也可能有用,如果您也在使用它。

【讨论】:

感谢您的帮助。我最初尝试了您的建议,但留下了额外的 [ 括号。【参考方案2】:

您可以使用此代码默认UITableViewCell有两个labelstextLabel用于正文和detailTextLabel用于详细文本。因此您可以通过textLabel.text访问UITableViewCell的文本标签

- (void)tableView:(UITableView *)tv1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

    [appDelegate muniClicked:[[tableView cellForRowAtIndexPath:indexPath] textLabel.text]];
    NSLog(@"cell clicked %d, %d", indexPath.row, indexPath.section);


【讨论】:

以上是关于“文本”已弃用的主要内容,如果未能解决你的问题,请参考以下文章

如何阻止 TinyMCE 用 span 替换已弃用的标签

UIAlertView 已弃用:首先在 iOS 9.0 中弃用 - UIAlertView 已弃用。将 UIAlertController 与首选样式一起使用

PHP 已弃用:each() 函数已弃用 [重复]

Modernizr.load 已弃用。 Yepnope.js 已弃用。怎么办?

已弃用:指令 'allow_url_include' 在第 0 行的 Unknown 中已弃用

DTD 是不是已弃用?