gpt4 book ai didi

ios - Obj-c - 使用更新的 NSMutableArray 重新加载 tableView

转载 作者:行者123 更新时间:2023-11-29 05:59:23 25 4
gpt4 key购买 nike

我正在尝试使用新数据(self.filtered,NSMutableArray)重新加载我的tableView。为了做到这一点,我的理解是我需要从原始 self.filtered 中删除所有对象,然后用更新的 NSMutableArray 重新填充它。然而,由于某种原因,当我运行下面的命令时,我收到以下崩溃错误(是的,所有值都按应有的方式填充......例如没有空响应):

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeAllObjects]: unrecognized selector sent to instance 0x28009c540'

Viewcontroller.h

@property (nonatomic, strong) NSMutableArray *filtered;

ViewController.m

-(void)viewDidLoad {
NSString *myID = [session user][@"user"][@"uid"];

NSPredicate *p1 = [NSPredicate predicateWithFormat:@"uid ==[cd] %@", targetedUser];
NSPredicate *p2 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", myID];
NSPredicate *p3 = [NSPredicate predicateWithFormat:@"uid ==[cd] %@", myID];
NSPredicate *p4 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", targetedUser];
NSPredicate *p5 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", universal];

NSCompoundPredicate *pIntermediary1 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1, p2]];
NSCompoundPredicate * pIntermediary2 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p3, p4]];
NSCompoundPredicate * pIntermediary3 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1, p5]];
NSCompoundPredicate *pFinal = [NSCompoundPredicate orPredicateWithSubpredicates:@[pIntermediary1, pIntermediary2, pIntermediary3]];

self.filtered = [self.messages filteredArrayUsingPredicate:pFinal];
}

- (IBAction)sendReply:(id)sender {
NSMutableArray *aArr = [NSMutableArray arrayWithObjects:self.filtered,nil];
NSLog(@"BEFORE IT %@", aArr);

[aArr addObject:nodeData];

[self.filtered removeAllObjects];
[self.filtered addObject:aArr];

[self.tableView reloadData];
NSLog(@"LASTLY %@", self.filtered);
}

此方法中没有 NSArray - 只有 NSMutableArray,所以我不确定为什么会发生这种情况?

最佳答案

行:

self.filtered = [self.messages filteredArrayUsingPredicate:pFinal];

给你一个NSArray,而不是一个NSMutableArray

将其更改为:

self.filtered = [[self.messages filteredArrayUsingPredicate:pFinal] mutableCopy];

然后你的代码就会工作得更好。在尝试设置 filtered 属性的任何行上检查这一点。

与该问题不同的是以下行:

[self.filtered addObject:aArr];

这是将数组添加到数组中,而不是直接将aArr的对象添加到filtered中。

将此行更改为:

[self.filtered addObjectsFromArray:aArr];

或替换行:

[self.filtered removeAllObjects];
[self.filtered addObject:aArr];

与:

self.filtered = aArr;

关于ios - Obj-c - 使用更新的 NSMutableArray 重新加载 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54832292/

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