在编辑模式

时间:2015-09-11 11:14:13

标签: ios iphone uitableview

UITableViewController正在加载多选和 ON EDIT 模式。

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];

....

    [self.tableView setEditing:YES animated:YES];
    self.tableView.allowsMultipleSelectionDuringEditing = YES;

}

结果就是这个: enter image description here

然而,这不是我想要的,因为我想在viewWillAppear之后选择一些单元格。

我想成为这样的

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ???

需要什么代码

我是否需要其他任何方法的代码?

1 个答案:

答案 0 :(得分:0)

您必须跟踪选定的内容,模型中可能是BOOL变量,NSArray中的indexPaths或其间的任何内容。

那么你应该对你做些什么cellForRowAtIndexPath

if( dataModel.shouldBeSelected == true){
    cell.imageView.image = [UIImage imageNamed:@"selected"];
}
else{
    cell.imageView.image = [UIImage imageNamed:@"empty"];
}

请注意,您必须处理未选择的单元格,以防止重复使用所选单元格并显示不正确的结果。