从 Core Data 的正确位置更新 UISearchBar 数据源
在我的应用程序中,我的表格视图上方有一个搜索栏。我的问题是这样的:
如果我进入表格视图并将一个项目添加到层次结构的任何级别,然后返回到根(搜索栏所在的位置)并尝试搜索它,它不会显示结果呢。
例如,如果应用程序启动时核心数据中已经有 itemOne 和 itemTwo,我可以很好地搜索并找到它们。但是,如果我添加 itemThree 并尝试搜索它,则找不到它。
我的搜索栏用于将 Core Data 中的所有项目加载到的数组位于 viewDidLoad 方法中:
- (void)viewDidLoad
{
listOfItems = [[NSMutableArray alloc] init];
NSMutableArray* allItemArray = [CoreDataHelper searchObjectsInContext:@"Item" :entitySearchPredicate :@"Description" :YES :managedObjectContext];
NSDictionary *allItemDict = [NSDictionary dictionaryWithObject:allItemArray forKey:@"Items"];
[listOfItems addObject:allItemDict];
}
我知道在添加最后一个项目后 viewDidLoad 没有运行,这就是我的问题。但我不知道将该代码放在哪里,它将使用已添加的任何项目进行更新。
任何意见都会受到赞赏。谢谢。
In my app, I have a search bar above my table view. My problem is this:
If I go into my table view and add an item to any level of the hierarchy, and then go back to the root (where the search bar is) and try to search for it, it doesn't show up in the results it.
For example, if I already have itemOne and itemTwo in core data when the app is launched, I can search and find them just fine. But if I add itemThree and try to search for it, it is not found.
The array that my search bar uses to load all of the items from Core Data into is located in the viewDidLoad method:
- (void)viewDidLoad
{
listOfItems = [[NSMutableArray alloc] init];
NSMutableArray* allItemArray = [CoreDataHelper searchObjectsInContext:@"Item" :entitySearchPredicate :@"Description" :YES :managedObjectContext];
NSDictionary *allItemDict = [NSDictionary dictionaryWithObject:allItemArray forKey:@"Items"];
[listOfItems addObject:allItemDict];
}
I know that the viewDidLoad isn't running after I add the last item, and that is my problem. But I don't know where to put this code that it will update with any items that have been added.
Any input is appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 viewWillAppear 上做同样的事情..事情会是正确的。
Do the same things on viewWillAppear ..things will be right.