简体   繁体   中英

Alternatives to loading core data on tabBar didSelectItem? Or speeding it up?

I am loading core data for my TableView on didSelectItem but this makes the tabbar feel sluggish where it won't update untill the new data has loaded. What is a good way to get around this issue? Can I update the tabbar and a blank tableview before the data has loaded or could I maybe show an activity indicator somehow?

This is my current code

- (void) tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSInteger index = [item tag];
NSMutableArray *schedule = [dataHandler fetchEntriesForCourse:[[_Courses objectAtIndex:index] valueForKey:@"CourseCode"]];
tableView.schedule = schedule;
}

You can make your fetch in the background thread, using GCD and populate the tableview as the data comes. Here is a great article on working with Core Data in the background thread.

http://www.cimgf.com/2011/05/04/core-data-and-threads-without-the-headache/

Really, if you catch data with fetchresultscontroller, all you'll need to do is make your fetch in another thread.And then it will automaticly catch add new rows, as the fetch goes on.

我最终制作了一个NSMutableArray来存储应用程序启动时的数据,因此选项卡的更改速度更快,因为它不必获取核心数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM