我有以下实现,用户可以根据需要选择尽可能多的项目。tableView上的对号标记
一旦用户选择该项目,我可以看到复选标记,但是当用户向上或向下滚动时,会出现奇怪的行为,因为我看到其他项目也被选中,即使未选中也是如此。
例如,如果我按顺序选择3个项目,当向下滚动时,我可以看到选定的相同图案(按顺序3个项目)。这是否与dequeueReusableCellWithIdentifier
有关?如果是,我做错了什么?
- (void)viewDidLoad {
[super viewDidLoad];
self.comboTableView.allowsMultipleSelection = YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[comboTableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[comboTableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return movies.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ((Section*)movies[section]).movies.count ;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = ((Section*)movies[indexPath.section]).movies[indexPath.row];
return cell;
}
复制https://stackoverflow.com/questions/23727255/multiple-checkmark-when-row-selected-in-uitableview-ios – Bejibun