gpt4 book ai didi

ios - 在填充有 JSON 的 NSArray 中搜索特定标题

转载 作者:行者123 更新时间:2023-11-29 03:38:58 25 4
gpt4 key购买 nike

我正在开发我的第一个严肃的 iPhone 应用程序,并且第一次使用 json。现在我的表格 View 上方有一个搜索字段,我想将数据过滤到输入的搜索文本。 JSON 看起来像这样:

{
"id":1,
"title":"Een Product",
"category":"Categorie",
"description":"Een Beschrijving",
"price":"10.00",
"image":"http:\/\/dev.smit-it.info\/APP\/LOGO\/een.png"
},

现在我希望能够按标题搜索,我正在尝试以下操作。

- (void) searchBarSearchButtonClicked:(UISearchBar *)sender
{
[self.SearchbarOnDisplay resignFirstResponder];
self.SearchbarOnDisplay.showsCancelButton=NO;

//ToDo:Get the search results
NSString *match = self.SearchbarOnDisplay.text;

self.SearchIsStarted = YES;

NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", match];
NSArray *ArrayWithFilteredContent;

ArrayWithFilteredContent = [self.dynamicData.DynamicRetrevedData filteredArrayUsingPredicate:sPredicate];
[self.tableView reloadData];

}

现在我设置了一些断点,问题是 self.dynamicData.DynamicRetrevedData 为 NIL。我不明白,因为这是 viewdidload 中的 alloc 和 init,并且数据当前显示在 tableview 中。如果它不为零,我如何指定它搜索标题。

希望你能帮忙,我已经尝试了两天了

最佳答案

首先是你的NSPredicate模式不对,应该是

NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"title CONTAINS[cd] %@", match]; // or @"title beginswith[c] %@" for alphabetically search.

但这不是其他问题。首先逐行检查代码,如果您的 tableView 的数据显示正确,那么它应该可以正常工作 self.dynamicData.DynamicRetrevedData

关于ios - 在填充有 JSON 的 NSArray 中搜索特定标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18736176/

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