小编jco*_*_82的帖子

表格视图重新加载部分崩溃

我有一个包含4个部分的表视图,每个部分有1-2个表视图单元格.第一个单元格具有uiswitch作为附件视图,并控制应用程序的颜色主题,在白天模式和夜晚模式之间切换.一旦按下开关,就会调用一个函数,改变导航栏的颜色和背景颜色.在那个功能中我也放了这条线

[self.tableview reloadData];
Run Code Online (Sandbox Code Playgroud)

使用新颜色更新表本身.它工作正常,但没有动画,所以我用它来代替

[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)] withRowAnimation:UITableViewRowAnimationFade];
Run Code Online (Sandbox Code Playgroud)

当使用该行时,开关卡住并且应用程序冻结.它不会崩溃,即没有崩溃日志,它只是冻结,uiswitch停止动画中期.

我注意到我可以重新加载没有包含附件视图的单元格的部分,并且它与淡入淡出动画完美配合.即这是有效的

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationFade];
Run Code Online (Sandbox Code Playgroud)

因为第三部分没有任何带附件视图的单元格.但任何包含附件视图的单元格(即第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 …
Run Code Online (Sandbox Code Playgroud)

objective-c reload uitableview ios sections

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

ios ×1

objective-c ×1

reload ×1

sections ×1

uitableview ×1