Reputation: 123
I have a function in Class A to show a view controller B when a button pressed. But I find that the view controller B's initial function (also contain viewdidload and viewwillapear) takes several seconds.
- (void)showCataloguesBook:(id)sender
{
UIButton *btn = (UIButton *)sender;
CataloguesCoverView *coverView = (CataloguesCoverView *)[_coversArray objectAtIndex:btn.tag];
NSString *bookID = [[self.dataArray objectAtIndex:btn.tag] objectForKey:@"bookID"];
PageCurlViewController *viewController = [[PageCurlViewController alloc] initWithNibName:nil bundle:nil];
viewController.defaultSize = coverView.image.size;
viewController.bookID = bookID;
[self presentViewController:viewController animated:YES completion:nil];
}
In view controller B's functions contain searching CoreData, adding subViewController (UIPageViewController) and so on, I couldn't improve it better. So, what I can do to reduce waiting time that between button pressed and show view controller B takes?
Upvotes: 0
Views: 100
Reputation: 3718
Caching.
A really simple scheme for doing this would be to set a property for viewController B and then instantiate it in the viewDidLoad
of viewController A and store it in the property, then it will be ready when you need to use it and you won't need to do any processing.
You should probably take precautions and make sure to get rid of the viewController in didReceiveMemoryWarning
.
If you need to do more try caching each possible option in an NSCache, which will manage the memory automatically. You could, if you wanted to get complex, run all of these in background threads when the app loads using NSOperationQueue and NSOperation.
You could also make a smaller query to save some of the information and present that immediately, and then do a larger query to grab more of the information later.
There is a lot of ways to do this, mostly you just need to come up with a smart way of storing some of the data before it is presented.
Upvotes: 1