[英]how to add the content of the cell of table view in other view when clicked on cell in objective-c
[英]Objective C: How to highlight the first cell in table view when view loads?
我试图默认在子视图出现时将表格视图中的顶部单元格突出显示。
我试图这样做:
switch(indexPath.row) { // assuming there is only one section
case 0:
cell.textLabel.text = @"First Cell:";
cell.highlighted = YES
break;
但这不起作用,因为我在第一个单元格上得到了黑色覆盖。
编辑(添加了屏幕截图)
任何对此的建议将不胜感激!
谢谢
震
我有同样的问题。 您需要将代码移动到willDisplayCell中,而不是cellForRowAtIndexPath中。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) {
[cell setSelected:YES animated:NO];
}
}
我想你需要的是
cell.selected = YES;
如果您希望将其设置为动画,则可以使用,
[cell setSelected:YES animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.