我使用下面的代碼來填充tableview行。在單擊一行時,我正在重新加載表數據,但行未被更新。 iOS的11之前,它工作正常,但在更新到iOS 11後我面對這個問題:UITableview單元格在reloaddata上不更新
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DayCell" forIndexPath:indexPath];
UILabel *label = [cell viewWithTag:101];
UIImageView *imageView = [cell viewWithTag:102];
NSArray *days = @[@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday"];
label.text = [days objectAtIndex:indexPath.row];
if ([_selectedDays containsObject:label.text]) {
imageView.image = [UIImage imageNamed:@"CheckedIcon"];
} else {
imageView.image = nil;
}
return cell;
}
,我在didSelectRowAtIndexPath方法是這樣重裝數據:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
UILabel *label = [cell viewWithTag:101];
if ([_selectedDays containsObject:label.text]) {
[_selectedDays removeObject:label.text];
} else {
[_selectedDays addObject:label.text];
}
[tableView reloadData];
}
難道我做錯了什麼?
如何將宣佈'_selectedDays' –
我初始化'_selectedDays'在'viewDidLoad'爲'_selectedDays = [NSMutableArray的新]' –
你把對象追加到'_selectedDays' –