Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2010, 09:58 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 82
idevelop7 is on a distinguished road
Default UIAcivitivyIndicatorView doesn't show up

Hi guys, I am having a problem with UIAcitivtyIndicatorView not showing up.
I have a tabbar application, in the first tab on clicking a record in a tableView, I am loading another ViewController:
Code:
[MyAppDelegate appDelegate].tabBarController.selectedViewController = [[MyAppDelegate appDelegate] SecondNavViewController];
In a viewWillAppear method of the SecondViewController, I have a function that takes some time to execute and I want to show my UIActivityIndicatorView (which is all created in AppDelegate) to the user like this:
Code:
- (void)viewWillAppear:(BOOL)animated
{
self.navigationItem.title = @"Home";
[[MyAppDelegate appDelegate] animateBusyPanelInView:self.view];
[self LoadData];
[[MyAppDelegate appDelegate] stopAnimatingBusyPanel];

/*rest of the code goes here*/
}
It works in other places in my app. but not in here. What am I doing wrong?

Thank you.
idevelop7 is offline   Reply With Quote
Old 07-07-2010, 10:26 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 82
idevelop7 is on a distinguished road
Default

Also, if I just StartAnimating the view without using StopAnimating, I can see the ActivityIndicator spinning.
idevelop7 is offline   Reply With Quote
Old 07-07-2010, 10:28 AM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

This issue has been answered tons of time on this forum. The short answer is that your loading is blocking the run loop from updating the UI to show the busyPanel. It would probably be better to spawn a thread to do your loading so that you dont block the UI updates.
smithdale87 is offline   Reply With Quote
Old 07-07-2010, 10:41 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 82
idevelop7 is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
This issue has been answered tons of time on this forum. The short answer is that your loading is blocking the run loop from updating the UI to show the busyPanel. It would probably be better to spawn a thread to do your loading so that you dont block the UI updates.
Thanks for replying to my question.
I tried using a separate thread, even a timer, but still have the problem.
When I use a separate thread - it executes the rest of my code first and then goes to "LoadData" method. What I need it to do is execute "LoadData" first - the rest of the code loads the data into a table and I need to get the data first.

Code:
- (void)viewWillAppear:(BOOL)animated
{
self.navigationItem.title = @"Home";	
	
[[MyAppDelegate appDelegate] animateBusyPanelInView:self.view];
[NSThread detachNewThreadSelector:@selector(LoadData) toTarget:self withObject:nil];

/*the rest of the code...*/
}

Last edited by idevelop7; 07-07-2010 at 10:43 AM.
idevelop7 is offline   Reply With Quote
Old 07-07-2010, 10:50 AM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

You can move the "rest of my code" part to anohter method, and call that from your thread that does the data loading. Let me explain:


Code:
- (void)viewWillAppear:(BOOL)animated
{
self.navigationItem.title = @"Home";	
	
[[MyAppDelegate appDelegate] animateBusyPanelInView:self.view];
[NSThread detachNewThreadSelector:@selector(LoadData) toTarget:self withObject:nil];

}
-(void)LoadData
{
    //load your data

   //finally
   [self performSelectorOnMainThread: @selector(dataLoadComplete) withObject:nil];
}

-(void)dataLoadComplete
{
   /*the rest of the code...*/
}

FYI, doing data loading in the viewWillAppear is generally a bad idea. Do it in your viewDidLoad so it only happens once, not every time the view comes on screen.
smithdale87 is offline   Reply With Quote
Old 07-07-2010, 02:06 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 82
idevelop7 is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
You can move the "rest of my code" part to anohter method, and call that from your thread that does the data loading. Let me explain:


Code:
- (void)viewWillAppear:(BOOL)animated
{
self.navigationItem.title = @"Home";	
	
[[MyAppDelegate appDelegate] animateBusyPanelInView:self.view];
[NSThread detachNewThreadSelector:@selector(LoadData) toTarget:self withObject:nil];

}
-(void)LoadData
{
    //load your data

   //finally
   [self performSelectorOnMainThread: @selector(dataLoadComplete) withObject:nil];
}

-(void)dataLoadComplete
{
   /*the rest of the code...*/
}

FYI, doing data loading in the viewWillAppear is generally a bad idea. Do it in your viewDidLoad so it only happens once, not every time the view comes on screen.
Thanks so much for your suggestion. However, I still have a problem.
I followed your advice and put "the rest of my code" into the "dataLoadComplete" method - it executes my "loading of the data" first, but it throws an exception:
Code:
-[SecondViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x1038a30
idevelop7 is offline   Reply With Quote
Old 07-07-2010, 03:33 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 82
idevelop7 is on a distinguished road
Default

It looks like it's pointing to the "tableView:numberOfRowsInSection" method which is in my (UITableViewDataSource), but I don't understand why it's pointing to it from SecondViewController. If I don't break the code like this, it is working fine. Anybody had an issue like this?
idevelop7 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 334
9 members and 325 guests
bignoggins, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0