gpt4 book ai didi

ios - 具有多个条件的 UITableView filteredArrayUsingPredicate?

转载 作者:行者123 更新时间:2023-11-28 20:03:59 24 4
gpt4 key购买 nike

我的工作:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"SELF.street contains[c] %@ OR SELF.id contains[c] %@", searchText];

self.filteredItems = [NSMutableArray arrayWithArray:
[self.items filteredArrayUsingPredicate:predicate]];

我想检查给定的 searchText 是在 ID 中还是在 STREET 属性中。 STREET 单独工作,但是一旦我添加 ID 检查我的应用程序崩溃。

知道如何在谓词中同时检查 ID 和 STREET 吗?

最佳答案

你使用了 %@ 两次,但只提供了一个参数,试试:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"SELF.street contains[c] %@ OR SELF.id contains[c] %@", searchText, searchText];

我将 ID 从 NSNumber 更改为 NSString。现在可以了。

关于ios - 具有多个条件的 UITableView filteredArrayUsingPredicate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22770251/

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