我有一个带有 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/