您好,在 iPad 应用程序中,我的 master controller
有列表,details controller 有其详细信息,典型的 UISplitViewController
模式.
我想要实现的是,我的第一行应该是最初选择的,然后我想给用户选择。
我正在使用单元格的 setSelected
并在 didSelectRowAtIndexPath
方法中删除这样的选择。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell* cell = [tableView cellForRowAtIndexPath:path];
[cell setSelected:NO];
}
用于初始单元格,但之后我的无单元格被选中 请帮助我。
最佳答案
要使单元格显示为选中状态,您必须从 -tableView:willDisplayCell:forRowAtIndexPath:
中调用 -setSelected:animated:
,如下所示:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (/* should be selected */) {
[cell setSelected:YES animated:NO];
}
}
从其他地方调用 -setSelected
无效。
关于ios - UITableViewCell 设置初始选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19295297/