加载UITableView
时,我希望选中only部分中的唯一行,以便在用户加载UITableView
时立即执行didSelectRowAtIndexPath
中的代码。我已经尝试了下面的代码,但它没有执行didSelectRowAtIndexPath
部分中的代码。有什么想法吗?
NSIndexPath *indexedPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView selectRowAtIndexPath:indexedPath animated:YES scrollPosition: UITableViewScrollPositionNone];
发布于 2013-04-25 20:47:36
使用此code.This将在加载视图时自动调用didSelectRowAtIndexPath
。
[self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
发布于 2013-04-25 20:52:06
如果你需要调用你在didSelectRowAtIndexPath
中使用的一些功能,你可以创建一个单独的方法,并将didSelectRowAtIndexPath
的所有逻辑放在你的单独方法中,然后从didSelectRowAtIndexPath
和其他你想调用相同代码的地方调用该方法?
如果你想在didSelectRowAtIndexPath方法中额外触发事件,你需要手动调用委托方法,它不会自动发生:
[self tableView:self.tableView didSelectRowAtIndexPath:your_indexpath];
希望能对你有所帮助。
发布于 2021-09-08 07:05:15
斯威夫特
let indexPath = IndexPath(row: 0, section: 0)
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .bottom)
tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)
https://stackoverflow.com/questions/16215004
复制相似问题