I have the following implementation where user could able to select as many item as he wants.
I could able to see checkmark once user selects the item, however when user scroll up or down, there is a strange behavior because I see other items are selected as well, even though it is not selected.
For example, if I select 3 items in order, when I scroll down, I could able to see same pattern (3 items in order) selected. is it something related with dequeueReusableCellWithIdentifier
? If yes, what I am doing wrong?
- (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;
}