我有以下實現,用戶可以根據需要選擇儘可能多的項目。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