gpt4 book ai didi

objective-c - 试图将 RowAtIndexPath 移动到另一个部分,iOS

转载 作者:行者123 更新时间:2023-11-28 22:50:44 27 4
gpt4 key购买 nike

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)oldPath toIndexPath:(NSIndexPath *)newPath {

if(oldPath.section == newPath.section && oldPath.row == newPath.row) return;

NSMutableArray * group = (NSMutableArray *) self.groups;
NSMutableArray *gItems = [group objectAtIndex:oldPath.section];
NSDictionary *item = [gItems objectAtIndex:oldPath.row];
[gItems removeObjectAtIndex:oldPath.row];
gItems = [group objectAtIndex:newPath.section];
[gItems insertObject:item atIndex:newPath.row];

[self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath];
}

试图在部分之间移动行。但是每次运行 [self.tableItems moveRowAtIndexPath:oldPath toIndexPath:newPath] 行时它都会崩溃,我做错了什么?提前告诉你。

最佳答案

你有一个“差一个”的错误:

if (newPath.row >= gItems.count) {
[gItems addObject: item];
} else {
[gItems insertObject: item atIndex:newPath.row];
}

关于objective-c - 试图将 RowAtIndexPath 移动到另一个部分,iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12066026/

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