Mobilewits
Mobilewits

Reputation: 1763

PresentModalViewController takes 5 secs to bring up the modal

I am trying to present a modal vc. But it takes like 5 secs or so n the delay appears to be significant as the user tries to tap on the button un till they see some thing on the screen.

My Modal view has 3 pages and each page has 6 tables as subviews. I am not using any network connectivity. All the tables are loaded from local xml data.

So, my questions are 1)is there a way i can improve the performance of the loaded modal vc? 2)or can i show an activity indicator and let the view load on a background thread and remove the indicator once the load is complete?

I tried option 2. I started the activity indicator on viewDidLoad and all the page Initialization code in a background thread using performSelectorInBackground method. But, this is making my tables to look weird like, there frame is all distorted , there width is screwed up n so on. Any suggestions will really help ma lot.

Upvotes: 0

Views: 550

Answers (2)

sudo rm -rf
sudo rm -rf

Reputation: 29524

Never show or modify interface elements in a background thread. If you're in a background thread and you want to do something in the main thread, you can either use a selector:

[self performSelectorOnMainThread:@selector(doSomething:)
                       withObject:someObject
                    waitUntilDone:NO];

or you can use GCD (my favorite):

dispatch_async(dispatch_get_main_queue(), ^{
    [self doSomething:someObject];
});

Regardless of which method you use, just make sure that if you load your data in a background thread and then try to load a view from that background thread, always do that call on the main thread, otherwise you will get the weird behavior you mentioned.

Upvotes: 2

Rahul Vyas
Rahul Vyas

Reputation: 28720

You can show activity indicator on viewDidAppear and then fetch data in background thread and you just need to refresh your view/tableview. This way modal view will not 5 seconds or delay when presented.

Upvotes: 0

Related Questions