我有一个包含 4 个部分的表格视图,每个部分有 1-2 个表格视图单元格。第一个单元格有一个 uiswitch 作为附件视图,控制应用程序的颜色主题,在白天模式和夜间模式之间切换。一旦按下开关,就会调用一个函数,更改导航栏的颜色和背景颜色。在该函数中我还添加了该行
[self.tableview reloadData];
使用新颜色更新表格本身。它工作正常,但没有动画,所以我用这个代替
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)] withRowAnimation:UITableViewRowAnimationFade];
当使用该线时,开关会卡住并且应用程序冻结。它不会崩溃,即没有崩溃日志,它只是冻结并且 uiswitch 在动画中停止。
我注意到我可以重新加载没有包含辅助视图的单元格的部分,并且它与淡入淡出动画完美配合。 IE。这有效
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationFade];
因为第三部分没有任何具有附属视图的单元格。但是,如果我尝试重新加载包含附件视图的单元格的任何部分(即第 0 部分和第 2 部分),应用程序就会冻结。
有什么想法为什么会发生这种情况吗?下面是我的 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
if (indexPath.section == 0) {
cell.textLabel.text = [section0 objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == 0) {
cell.accessoryView = colorSchemeSwitch;
}
else if (indexPath.row == 1) {
cell.accessoryView = autoLockSwitch;
}
}
else if (indexPath.section == 1) {
cell.textLabel.text = [section1 objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else if (indexPath.section == 2) {
cell.textLabel.text = [section2 objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i \t", (int)app.fontSize];
fontSizeSlider.value = app.fontSize;
cell.accessoryView = fontSizeSlider;
}
else if (indexPath.section == 3) {
cell.textLabel.text = [section3 objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.text = app.color;
}
cell.backgroundColor = app.cellBackgroundColor;
cell.textLabel.textColor = app.textColor;
UIView *backgroundColorView = [[UIView alloc] init];
backgroundColorView.backgroundColor = app.cellSelectedColor;
[cell setSelectedBackgroundView:backgroundColorView];
return cell;
}