我制作了一个大型的UITableView
和27个静态UITableViewCell
s。当选择一个UITableViewCell
应该设置其accessoryType
到UITableViewAccessoryCheckmark
,并最后选定UITableViewCell
的accessoryType
到UITableViewAccessoryNone
:UITableViewCell无法在大型UITableView中看到(Xcode,iOS)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// get an NSInteger from NSUserDefaults
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:savedInteger inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
[self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:savedInteger inSection:0]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the NSInteger again
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:savedInteger inSection:0]];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
lastCell.accessoryType = UITableViewAccessoryNone;
cell.accessoryType = UITableViewAccessoryCheckmark;
// save indexPath.row in NSUserDefaults and do some other stuff
,当你选择一个UITableViewCell
是接近最后选定UITableViewCell
但是当最后选定的这工作得很好UITableViewCell
大约有11行左右,UITableViewCell *lastCell
是nil
并且复选标记不会消失。
为什么它的行为如何,我该如何解决它?提前致谢。因为UITableView的重用细胞(当您从顶部滚动细胞它初始化只有少数细胞进入底部等,它是有效的)
看到类似的问题
不显式调用'didSelectRowAtIndexPath'。 – rmaddy
您应该在'cellForRowAtIndexPath'中设置单元的accessoryType。 – rmaddy
在你的模型对象中有1个布尔,并且从那个布尔你可以处理accessoryView。 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath'但是当我尝试使用UITableViewCell获取单元格时,如果bool是真的然后显示它,否则不要.. –