ios - 如何获取 UITableView Label 文本字符串 - Custom Cell

标签 ios objective-c string uitableview

我有一个带有 CustomCell 的 UITableView。自定义单元格包含一个 UILabel 和一个 UIImageView。

我在网上看到可以在用户按下单元格时从普通的 UITableView 单元格中获取文本并将其存储在字符串中。

但是当您使用自定义单元格时,您如何做到这一点呢?因为我的 UILabel 的名称是“type_label”,它已在我的 CustomCell XIB 的头文件中定义。

所以在 Xcode 中我不能使用:

cell.type_label.text"

在下面的函数中:

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

谢谢,丹。

最佳答案

在 tableViewDidSelectRow 中,您需要做的就是:

UITableViewCellCustomClass *customCell = (UITableViewVellCustomClass*)[tableView cellForRowAtIndexPath:indexPath];

NSString *labelText = [[customCell type_label] text];

这应该能满足您的需求。

关于ios - 如何获取 UITableView Label 文本字符串 - Custom Cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18618769/

相关文章:

mysql - 使用我的 iOS 应用程序连接到 MySQL 数据库

c# - 用双引号将每个单词括起来

c++ - const char*, char const*, const char const* & 字符串存储的区别

ios - Fat XIB 的内存问题

ios - 导航栏和标签栏没有一起出现

ios - 使用 CAGradientLayer 定义渐变的角度

c++ - 在文件中写入新行字符

ios - 为什么通用应用程序的ipa是300mb?

ios - UITableView HeaderView 上的 SearchDisplayController 怪异行为

ios - Objective C 冒充与多态性/方法覆盖