gpt4 book ai didi

iOS UITableView 行在 reloadSections 上消失 :withRowAnimation

转载 作者:行者123 更新时间:2023-12-02 02:36:01 26 4
gpt4 key购买 nike

我有一个使用 Storyboard设计的静态表格 View 。每当我选择一个单元格并调用 reloadSections:withRowAnimation: 时,它都会导致其上方的两个单元格消失,但显示应有的 4 个单元格。有人知道为什么会发生这种情况吗?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

if (indexPath.section == 1) {
if (indexPath.row == 0) {

}
else if (indexPath.row == 1) { // Map Type Cell

self.isSelectingMapType = ![self isSelectingMapType];
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
else {

// Configure the single selection
if (self.checkedIndexPath) {
UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:self.checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}

// Check the cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;

// Store the new indexPath
self.checkedIndexPath = indexPath;

// Save the map type indexPath
[LBSettings saveObject:indexPath forKey:kLBSettingsMapTypeIndexPath];

// Save the map type
if (indexPath.row == 2) {

// Save the map type standard
[LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeNormal] forKey:kLBSettingsMapType];
}
if (indexPath.row == 3) {

// Save the map type satellite
[LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeSatellite] forKey:kLBSettingsMapType];
}
if (indexPath.row == 4) {

// Save the map type hybrid
[LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeHybrid] forKey:kLBSettingsMapType];
}
if (indexPath.row == 5) {

// Save the map type terrian
[LBSettings saveObject:[NSNumber numberWithInt:kGMSTypeTerrain] forKey:kLBSettingsMapType];
}

self.isSelectingMapType = ![self isSelectingMapType];
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in each section
switch (section) {
case 0:
return 3;
break;
case 1:
if (self.isSelectingMapType == YES) {
return 6;
}
return 2;
break;
case 2:
return 2;
break;
case 3:
return 6;
break;
case 4:
return 0;
break;
default:
break;
}
return 0;
}

最佳答案

尝试在动画事务完成后调用 reloadData。

[CATransaction begin]; 

[CATransaction setCompletionBlock:^{
[self.tableView reloadData];
}];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];

[CATransaction commit];

关于iOS UITableView 行在 reloadSections 上消失 :withRowAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17913528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com