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-09-2010, 03:33 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default load/progress of loading another view?

Hello,

I have been looking for a solution for two days now, but I can't find it

My appDelegate is sending the user to mainView, on mainView are 4 buttons in a table, an if statement determines what buttons is being tapped.

In the if statement is a [self presentmodalViewController:exampleScreen animated: NO];

in the exampleScreen .m file is a loadData and is loading stuff from the internet using a JSON parser

The problem is that when the user taps a button, the screen looks frozen, but it loads the data on the mainView and after loading it shows the next screen with the loaded data...

Does anyone knows how to just load the tapped screen and THEN load the data? without the user having to tap another button?

I tried to start animating an activityIndicator in the viewDidLoad, put a sleep(1) after that and after that the [self loadData], but then the sleep is being casted on the mainView....

Pls help!
rickrets is offline   Reply With Quote
Old 07-09-2010, 03:49 AM   #2 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

Try calling loadData in the viewDidAppear method of exampleScreen, so it's called once the view has appeared.
If it's being called in viewDidLoad, then it's being executed once the controller is loaded, which is probably before it's being presented, hence the delay Alternatively you could also do your parsing in a new thread, which should allow the view to be presented without the freezing.
__________________
appz

Last edited by refreshe; 07-09-2010 at 03:52 AM.
refreshe is offline   Reply With Quote
Old 07-09-2010, 03:54 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Yes that's what I was thinking, but that doesn't work

##exampleScreen.m##
- (void)loadData {
//JSON parser
}

- (void)viewDidLoad {
[self loadData];
}

But that doesn't work...

So I tried to put an activityIndicator on the center of the screen in IB in the exampleScreen.xib, but the stupid part is, is that the screen on mainView looks frozen (while it's loading the exampleScreen - the JSON data?), THEN the exampleScreen pops up with the loaded data and the activityindicator shows up like a .5 secs or so and then dissappears because at that time the data is already loaded

It's not at all user friendly if I won't let the user know something is being loaded
rickrets is offline   Reply With Quote
Old 07-09-2010, 04:00 AM   #4 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

No I mean try calling it in viewDidAppear:

Code:
- (void)viewDidAppear:(BOOL)animated {

    [self loadData];
}
__________________
appz
refreshe is offline   Reply With Quote
Old 07-09-2010, 04:08 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

That way it still loads in the mainView, but then shows no data after loading, my app hates me or something


The code in mainView btw:

exampleView *exampleScreen = [[exampleView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:exampleScreen animated:NO];

I tried:

viewDidLoad
viewDidAppear
awakeFromNib

I tried to put a stupid loop in all these above like:

for (int i = 0; i < 1; i++) {

if (i =0){
[activityIndicator startAnimating];
} else {
[self loadData];
}

}

(the JSON fills an array, when the filling is done i had a stopAnimating..)
rickrets is offline   Reply With Quote
Old 07-09-2010, 04:28 AM   #6 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

lol maybe I'm confused as to how the app is set up. I'm assuming that you have 2 view controllers: mainView and exampleScreen. When you press a button in mainView, it brings up (modally) the exampleScreen. exampleScreen has a method called loadData that is meant to be called when the screen is shown, that parses data & updates exampleView's UI with the data?

Also have you tried calling loadData in a separate thread so it doesn't block the UI (then update the UI on the main thread after parsing is done)?

Code:
	[NSThread detachNewThreadSelector:@selector(loadData) toTarget:self withObject:nil];
__________________
appz
refreshe is offline   Reply With Quote
Old 07-09-2010, 04:31 AM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

I was just browsing around and found this:

How are you loading your data? Make sure it isn't using synchronous networking. If it is, that's your problem - synchronous network calls block the entire app. You can't update the UI while they run. Either use async networking or run the sync stuff in a separate thread.

it is a synchronous request in my app!

How do I implement that line of code you posted?
I'm fairly new to xcode!

(you are right about the set-up of the app by the way)
rickrets is offline   Reply With Quote
Old 07-09-2010, 04:38 AM   #8 (permalink)
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

Might not be exactly right, but off the top of my head something like:

Code:
- (void)viewDidLoad {

    [NSThread detachNewThreadSelector:@selector(loadData) toTarget:self withObject:nil];
}

- (void)loadData {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    //parse the data

    [self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];		

    [pool release];
}

- (void)updateUI {
    
    //load parsed data into labels/whatever
}
__________________
appz
refreshe is offline   Reply With Quote
Old 07-09-2010, 05:05 AM   #9 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Wow, I guess it's working! I did get an error, but after some testing i found out why the error occured...

I'm filling a table with the loaded data, so I tried this:

[self performSelectorOnMainThread:@selector(tableView) withObject:nil waitUntilDone:NO];

The table code:

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

blablablabla cell being filled blabla return cell;
}

How can I get that to work?

Now i just made an empty - (void)test { } and stopped the activityIndicator before [pool release]; and that is working (the indicator looks like it's lasting as long as the loading is supposed to happen..)

Many thanks so far anyway!
rickrets is offline   Reply With Quote
Old 07-09-2010, 05:38 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Hmm, I've added this to:

example.h:
IBOutlet UITableView *table;
@property (nonatomic, retain) IBOutlet UITableView *table;

example.m:
@synthesize table;

Then I added this:

- (void)test {
[table reloadData];
}

and called the test in the performSelectorOnMainThread, but this makes my app crash...

then I changed the test to:

- (void)test {
//[table reloadData];
UIAlertView *alert [[.......]....];
}

I do receive the alert after the loading is done, I just can't get the table to be filled after the loading... Anyone else knows how to do this?


Edit: Yes, I also connected the table in IB...
rickrets is offline   Reply With Quote
Old 07-09-2010, 07:19 AM   #11 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

I got it to work finally

Thanks for your help refreshe!!!!
rickrets 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: 341
14 members and 327 guests
akphyo, cgokey, EXOPTENDAELAX, flamingliquid, GHuebner, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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