作者:米字格时光 | 来源:互联网 | 2023-08-18 14:09
ThisseemslikeasimplethingbutImstuck.这看起来很简单,但我被卡住了。Inmystoryboard,Ihaveacellwith
This seems like a simple thing but I'm stuck.
这看起来很简单,但我被卡住了。
In my storyboard, I have a cell with text in it's label (using Static Cells). In didSelectRowAtIndexPath, I'm trying to access the cell's textLabel's text. Here's my code, with NSLogging:
在我的故事板中,我有一个带有文本标签的单元格(使用静态单元格)。在didSelectRowAtIndexPath中,我正在尝试访问单元格的textLabel文本。这是我的代码,使用NSLogging:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.textLabel.text) {
NSLog(@"cell.textLabel.text = %@",cell.textLabel.text);
} else {
NSLog(@"!cell.textLabel.text");
}
NSLog(@"just for fun: cell.textLabel.text = %@", cell.textLabel.text);
The if statement always returns "!cell.textLabel.text" and the last NSLog is always (null) although the storyboard's cell has text in it.
if语句始终返回“!cell.textLabel.text”,最后一个NSLog始终为(null),尽管故事板的单元格中包含文本。
Is cell.textLabel not correct? Should I be looking at another subview of UITableViewCell?
cell.textLabel不正确吗?我应该查看UITableViewCell的另一个子视图吗?
1 个解决方案