cgo*_*ain 17 iphone cocoa-touch ipad ios4
我想知道是否有一种方法可以让我的代码"点击"我的UITableView中的一个单元格,以便重现- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath委托方法中指定的行为.
我想换句话说,是否可以以- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath编程方式调用委托方法?
Ben*_*lin 36
如果您想要选择单元格,即突出显示特定单元格:
//select first row of first section
NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:selectedCellIndexPath animated:false scrollPosition:UITableViewScrollPositionMiddle];
Run Code Online (Sandbox Code Playgroud)
如果你想在didSelectRowAtIndexPath方法中另外触发动作,你需要手动调用委托方法,它不会自动发生:
[self tableView:self.tableView didSelectRowAtIndexPath:selectedCellIndexPath];
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23366 次 |
| 最近记录: |