我正在使用 iPad 中的 SplitViewController 处理 MasterDetail 视图,我的主视图有一个 tableView,我在其中动态添加行。因此,新添加的行位于零位置。所以我想要实现的是,我想在新添加的行添加到主表后立即选择它。稍后当用户添加新行时,应选择该行并取消选择先前添加的行。
为此,我编写了下面的代码
- (void)selectNewlyAddedRow
{
NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0];
[m_tableView selectRowAtIndexPath:selectedCellIndexPath animated:TRUE scrollPosition:UITableViewScrollPositionNone];
[self tableView:m_tableView didSelectRowAtIndexPath:selectedCellIndexPath];
}
如果我在函数 ViewDidAppear 中编写此代码有效,但如果我在 cellForRowAtIndexPath 中编写它,则它不起作用..
请让我正确理解我哪里出错了。
问候兰吉特