我想知道有没有一种方法可以让我的代码“点击”我的UITableView中的一个单元格,以便重现- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
委托方法中指定的行为。
我猜换句话说,有没有可能以编程方式调用- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
委托方法?
发布于 2011-05-07 08:33:02
难道你不能把didSelectRowAtIndexPath中的任何逻辑放到一个单独的方法中,然后从didSelectRowAtIndexPath和任何你想调用相同代码的地方调用那个方法吗?
发布于 2012-01-06 06:44:58
如果您想要选择单元格,即突出显示特定的单元格:
//select first row of first section
NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:selectedCellIndexPath animated:false scrollPosition:UITableViewScrollPositionMiddle];
如果你想在你的didSelectRowAtIndexPath方法中触发额外的动作,你需要手动调用委托方法,它不会自动发生:
[self tableView:self.tableView didSelectRowAtIndexPath:selectedCellIndexPath];
发布于 2017-07-26 22:25:34
Swift 3.2解决方案
let indexPath = IndexPath(row: 2, section: 0) // change row and section according to you
tblView.selectRow(at: indexPath, animated: true)
tblView.delegate?.tableView!(tblView, didSelectRowAt: indexPath)
https://stackoverflow.com/questions/5918309
复制相似问题