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 02-08-2012, 08:06 AM   #1 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default ActivityIndicator for TabbedBar Application

Hi, I have a tabbed bar application. sometime when I click on tab Bar Item, if the internet speed is slow, then it takes time to show the tabBarItem which is clicked already for few seconds, I want to display activity indicator if it takes time to show the tabBarItem. other times when internet is in good speed and it is opening quickly then i dont need it in that case.

Thanks looking forward for help.
Sunny46 is offline   Reply With Quote
Old 02-08-2012, 08:35 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You have it set up wrong if switching to the tab takes a while. You should make it so that you can switch to the tab right away, and then if downloading needs to happen, it doesn't start until the view is shown. And if it could take a while, then the downloading should be done asynchronously.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 08:56 AM   #3 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You have it set up wrong if switching to the tab takes a while. You should make it so that you can switch to the tab right away, and then if downloading needs to happen, it doesn't start until the view is shown. And if it could take a while, then the downloading should be done asynchronously.
Hi, Thanks for response, Actually I am using JsonSearlization object on almost every tabBar Item, I get data from remote location in a Dicationary and load using ViewwillAppear of every tabBar Item..
Code:
[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&serverError]
.

The case i talked about, sometimes the data from the remote location can be huge and loading in Tables, on different tab bar items i am updating the data also and data is readily available after updating when i switch to see the data on other baritem. and when using no-WIFI or internet speed is low, then this is taking time... otherwise tabBar items are changing instantly.

Last edited by Sunny46; 02-08-2012 at 10:04 AM.
Sunny46 is offline   Reply With Quote
Old 02-08-2012, 10:38 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok, so did you actually read what I said?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 11:31 AM   #5 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Ok, so did you actually read what I said?
Yes I read what you said... I know how to do asynchronous request but that is the case when you use NSURLConnection, I am using a NSJsonSearlized object and in that I dont know any asychronous or synchronous request... I see your sarcasm, but I read your post. I have actually tried to show activityindicator when current tabbar item willDisappear method and as well as the next tab bar item willappear method... but it does not work for me.
Sunny46 is offline   Reply With Quote
Old 02-08-2012, 12:03 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, you are doing that code in viewWillAppear, so it is always going to happen before you can switch to the tab. That's why you have to wait. If you change that to viewDidAppear, that alone will help.

I'm also reasonably certain that NSJSONSerialization has nothing to do with it. Where does your data come from?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 12:15 PM   #7 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Well, you are doing that code in viewWillAppear, so it is always going to happen before you can switch to the tab. That's why you have to wait. If you change that to viewDidAppear, that alone will help.

I'm also reasonably certain that NSJSONSerialization has nothing to do with it. Where does your data come from?
thanks, I will try this willdidAppear, my data comes from a remote php page.
Sunny46 is offline   Reply With Quote
Old 02-08-2012, 01:09 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by Sunny46 View Post
thanks, I will try this willdidAppear, my data comes from a remote php page.
I knew you were going to say something like that, and I knew it would be a useless answer.

The code. How are you getting the data in code?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 01:22 PM   #9 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
I knew you were going to say something like that, and I knew it would be a useless answer.

The code. How are you getting the data in code?
It could be useless but I have tried it nothing has changed.

I get the data in a NSDictionay because I have data in a form of big dictionary, which includes single values and values as array also. so i just get the values for particular keys and if it is array then i just traverse the array using loop and it shows the data.

Code:
    NSDictionary *response=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&serverError];
Sunny46 is offline   Reply With Quote
Old 02-08-2012, 01:39 PM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Why do you think that showing me the same line of code again is useful?

data. data. Where does data come from? data. Need to know about data. data. data. I don't care about JSON. data. How do you get data? data. data.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 02:02 PM   #11 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by BrianSlick View Post
Why do you think that showing me the same line of code again is useful?

data. data. Where does data come from? data. Need to know about data. data. data. I don't care about JSON. data. How do you get data? data. data.
LOL. Don't you care about NSJasonSerialization?

I wonder if he'll hear your question this time?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-08-2012, 02:07 PM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by Sunny46 View Post
It could be useless but I have tried it nothing has changed.
I'm also going to guess that you did it wrong. So rather than showing the same line of code over and over again, copy-paste the ENTIRE method. I swear I don't understand why new people think their code is top secret.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 02:12 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

You should do all webservice calls using a background thread:

[self performSelectorInBackground:@selector(doIt) withObject:nil];

-(void)doIt {
NSAutoreleasePool *aPool = [NSAtoreleasePool alloc] init];

// code here

[aPool drain];
}
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 02-08-2012, 02:53 PM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by RickSDK View Post
You should do all webservice calls using a background thread:
No, he should do an asynchronous call.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-09-2012, 02:45 AM   #15 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Why do you think that showing me the same line of code again is useful?

data. data. Where does data come from? data. Need to know about data. data. data. I don't care about JSON. data. How do you get data? data. data.
data comes like this... if I answer your question again... i hope it can help to understand what you asked in last message...
Code:
 NSString *urlString=[NSString stringWithFormat:@"%@getData.php",appUrl];    
    
    
    NSURL *url=[NSURL URLWithString:urlString];
    
    NSData *data=[NSData dataWithContentsOfURL:url];
    
    NSError *error=nil;
    
    NSDictionary *response=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 07:09 AM   #16 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

And now I have Implemented the functionality using asynchronous request... but it makes my app more miserable. using the above line of code which i wrote before... was must faster... than this.. now...

Code:
 -(void)LoadDataFromURL:(NSString*)urlString{

        NSString *requestUrl = [NSString stringWithFormat:urlString];
        

        NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:requestUrl]];
        

        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        
        // Send an asyncronous request on the queue
    [NSURLConnection
     sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,
                                                                        NSData *data, NSError *error) {
            
            // If there was an error getting the data
            if (error) {
                
// show alert                
                   }
            
            NSError *jsonError;
            NSDictionary *response = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
            
            // If there was an error decoding the JSON
            if (jsonError) {
                 // show alert
                  }         
                    
      // load the data into the fields 
        [self updateDetailswithDictionary:response];   
     } ];

}
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 08:00 AM   #17 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

There is no reason for that to be any slower. You've done something wrong.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-09-2012, 08:11 AM   #18 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
There is no reason for that to be any slower. You've done something wrong.
and what you see something wrong in this code ??? this is all the request... don't you think if something wrong should be happening... happening here.. only that the data from dictionary is loading on a table cells.... so I assign the values in the list and then add to the cells of tableview...
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 08:28 AM   #19 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You need to start using specifics, because you don't explain yourself well at all. "More miserable" means what, exactly? It was taking 0.5 seconds to download before, and now it takes 10? What?

I'm still waiting for you to prove that you did the viewDidAppear part correctly.

Start providing useful information, or I'm going to get bored and leave this thread.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-09-2012, 08:33 AM   #20 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You need to start using specifics, because you don't explain yourself well at all. "More miserable" means what, exactly? It was taking 0.5 seconds to download before, and now it takes 10? What?

I'm still waiting for you to prove that you did the viewDidAppear part correctly.

Start providing useful information, or I'm going to get bored and leave this thread.
Yes, I understand your point, when i implemented without asynchronous request, using only jsonObject, it was loading when screen was loading. Now after asynchronous request I have to wait more than 5 seconds. I dont think it is a mystery to implement viewDidAppear method ??? I called the method which is sending the request in the viewDidAppear Method.. this is what i do...

I know it could be boring for you but I feel it is writing exactly how it should be and still not working... :O
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 08:37 AM   #21 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You need to start using specifics, because you don't explain yourself well at all. "More miserable" means what, exactly? It was taking 0.5 seconds to download before, and now it takes 10? What?

I'm still waiting for you to prove that you did the viewDidAppear part correctly.

Start providing useful information, or I'm going to get bored and leave this thread.
I have one more method where i write the complete url and call the above asynchronous request method
here is how i do what i do...
Code:
 

 -(void) update{
    NSString *urlString=[NSString stringWithFormat:@"%@getData.php",self.appDelegate.url];    
    
// calling the method which sends the asynchronous request
    [self downloadDatafromURL:urlString];
 }


-(void)viewDidAppear:(BOOL)animated {

    
    [super viewDidAppear:animated];

    [self update];

    
 }
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 08:40 AM   #22 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, you didn't know to try viewDidAppear in the first place, so you don't have much experience.

You didn't know that this should be done with an asynchronous request, so you don't have much experience.

You keep pointing to your JSON parsing as proof that you can't do an asynchronous request, which means you don't really know what you are doing.

You provide very bad answers to questions, which demonstrates that you don't really understand what is being said.

Which part of this means that I should trust what you are doing at all? So when you come back and say "this change didn't matter" or "now it is worse", why should I believe that you did it correctly? You haven't demonstrated any skills yet. So in the absence of skill, you should post code. Not explanations, code.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-09-2012, 08:42 AM   #23 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Well, you didn't know to try viewDidAppear in the first place, so you don't have much experience.

You didn't know that this should be done with an asynchronous request, so you don't have much experience.

You keep pointing to your JSON parsing as proof that you can't do an asynchronous request, which means you don't really know what you are doing.

You provide very bad answers to questions, which demonstrates that you don't really understand what is being said.

Which part of this means that I should trust what you are doing at all? So when you come back and say "this change didn't matter" or "now it is worse", why should I believe that you did it correctly? You haven't demonstrated any skills yet. So in the absence of skill, you should post code. Not explanations, code.
Here i post the code again about viewDidAppear method, I have just posted above also..before you answered...

Code:
 -(void) update{
    NSString *urlString=[NSString stringWithFormat:@"%@getData.php",self.appDelegate.url];    
    
// calling the method which sends the asynchronous request
    [self downloadDatafromURL:urlString];
 }


-(void)viewDidAppear:(BOOL)animated {

    
    [super viewDidAppear:animated];

    [self update];

    
 }
Sunny46 is offline   Reply With Quote
Old 02-09-2012, 08:43 AM   #24 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Are you still doing the synchronous request in viewWillAppear?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-09-2012, 08:46 AM   #25 (permalink)
Survivor
 
Join Date: Jan 2012
Posts: 41
Sunny46 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Well, you didn't know to try viewDidAppear in the first place, so you don't have much experience.

You didn't know that this should be done with an asynchronous request, so you don't have much experience.

You keep pointing to your JSON parsing as proof that you can't do an asynchronous request, which means you don't really know what you are doing.

You provide very bad answers to questions, which demonstrates that you don't really understand what is being said.

Which part of this means that I should trust what you are doing at all? So when you come back and say "this change didn't matter" or "now it is worse", why should I believe that you did it correctly? You haven't demonstrated any skills yet. So in the absence of skill, you should post code. Not explanations, code.
Yes you are right that I did not know in the start but I have implemented that and I showed the code also... If you can not see the code then i post here again and tell me where I am not doing the asynchronous request???? I would be beginner but don't tell me that I am stupid even I write the whole request and it is taking time to show the results...


Code:

 -(void)LoadDataFromURL:(NSString*)urlString{

        NSString *requestUrl = [NSString stringWithFormat:urlString];
        

        NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:requestUrl]];
        

        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        
        // Send an asyncronous request on the queue
    [NSURLConnection
     sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,
                                                                        NSData *data, NSError *error) {
            
            // If there was an error getting the data
            if (error) {
                
// show alert                
                   }
            
            NSError *jsonError;
            NSDictionary *response = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
            
            // If there was an error decoding the JSON
            if (jsonError) {
                 // show alert
                  }         
                    
      // load the data into the fields 
        [self updateDetailswithDictionary:response];   
     } ];



    NSString *urlString=[NSString stringWithFormat:@"%@getData.php",self.appDelegate.url];    
    
// calling the method which sends the asynchronous request
    [self downloadDatafromURL:urlString];
 }


-(void)viewDidAppear:(BOOL)animated {

    
    [super viewDidAppear:animated];

    [self update];

    
 }
Sunny46 is offline   Reply With Quote
Reply

Bookmarks

Tags
activityindicator, uitabbarcontoller

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: 390
12 members and 378 guests
7twenty7, chiataytuday, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, ryantcb, stanny, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

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