Results 1 to 6 of 6
  1. #1


    Member Since
    Jun 03, 2011
    Posts
    54
    UIActivityIndicator problem
    Dear All,

    In my spliview based app, once I tap the file name located on main view panel, one jsp (that lies on some server) is called and then jsp returns the file location on server. Then I create NSURLConnection object to stram the file from that location and save the file to application document directory. Once streaming is completed, I pass the file's local location (as id type) to detailitem in detilviewcontroller. And then file is viewed in uiwebview in detailview.
    Everything is happening properly.

    But what I want is that as soon as jsp is called and while it takes time to stream the file locally , activityindicator should rotate in detailview, so that user has ad idea that something is happening.And as soon as file is loaded in webview (after file is streamed and available locally), that indicator is stopped.


    I am sure this has to do something with delegat method of NSURLConnection, but I am unable to implement it properly. Also, I know the exact file size as soon as I tapped the file (Is that of any use?? May be If I use progressbar).


    Part of code is:

    - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:
    (NSIndexPath *)indexPath {

    NSString *post = [NSString stringWithFormat:@"DocId=%@",docid];
    NSData *postdata = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
    file_expected_size=[[file_size_list objectAtIndex:indexPath.row] longLongValue];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",DV_instance,@"/jsp/DV3_CreateFileLink_iPad.jsp"]]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody: postdata];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if(conn){

    NSURLResponse *response;
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    NSString *serveroutput= [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
    NSString *stringurl = [serveroutput stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSURL *url_for_filetapped_on_Server = [NSURL URLWithString:stringurl];
    NSData *data_of_file = [NSData dataWithContentsOfURL:url_for_filetapped_on_Server];



    // Then I determine the local file path (which is relative_local_file_full_path) and then

    detailview.detailItem =relative_local_file_full_path; (where detailview is an object of class DetailViewController)

    }
    }

    Any idea is appreciated!!
    Thanks

  2. #2

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    187
    I would first create an IBOutlet variable for the UIActivityIndicatorView class, in the header
    file for your controller class, and add the NSURLConnection protocol attribute to the class,
    like this.

    Code:
    @interface className : NSObject  <NSURLConnectionProtocol>
    {
            IBOutlet  UIActivityIndicatorView  *activityIndicator ;
    }
    Then connect the ActivityIndicatorView in your xib file to this outlet, also set the hidden
    property to true, and the hides when stopped property to true, using the attributes inspector.

    then you would call the startAnimating: method on the activityIndicator variable, from the
    method you use to start the NSURLConnection request, like this.

    Code:
    - (void)startConnection
    {
          [activityIndicator startAnimating] ;
    }
    And use the stopAnimating: method of the activityIndicator, from the method you use to
    verify the connection data has been recieved, like this.

    Code:
    - (void)stopConnection
    {
          [activityIndicator stopAnimating] ;
    }
    In iOS 4.3 the NSURLConnection has a connectionDidFinishLoading : method, and a
    delegate method connection : didFailWithError : , which you could use to stop the
    activity indicator in either case, but I'm not sure if these methods are still available in iOS 5.

    Check out the developer documentation, on the NSURLConnection class, and delegate
    methods to find the appropriate methods for checking the completed download.

    This guide is probably worth reading as well.

    https://developer.apple.com/library/.../uid/10000165i

    Hope this is of some help.

    Regards Mark

  3. #3


    Member Since
    Jun 03, 2011
    Posts
    54
    Thanks for quick reply but I am not creating GUI using interface builder rather I m making splitviewer programatically.

    So, when I tap a file in mainview, activityindicator should start in detailview.
    So, when NSURLConnection class and delegates are being used in mainview class then how can I relate this with the activity indicator which is in detailview?

    Thanks

  4. #4

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    187
    The UIActivityIndicatorView is a subclass of UIView, so you can create the activity indicator
    with code like this.

    Code:
    //in your header file
    
    @interface yourView : UIView
    {
            UIActivityIndicatorView *indicatorView;
    }
    
    //in the appropriate method in your view controller implementation file
    
        indicatorView = [[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [indicatorView setHidden:NO];
        [indicatorView hidesWhenStopped];
        [indicatorView startAnimating];
        [self addSubview:indicatorView];
        [self setNeedsDisplay];
        [indicatorView release];
    You will have to set the position of the indicatorView in the super view, in the same way
    you would with any view object, for the example, above I simply tested the code in a UIView
    that I dragged on to a blank window application, so did not bother with the position.

    Also you will have to stop the UIActivityIndicatorView in the appropriate method like this.

    Code:
    [indicatorView stopAnimating];
    Hope this helps.

    Regards Mark
    other view object

  5. #5


    Member Since
    Jun 03, 2011
    Posts
    54
    Thanks for the reply.
    I got the problem. It seems that indicator placement is not possible with synchronous nsurlconnection.
    While I changed it to asynchronous, I could properly placed, started and stopped the indicatorview.

    Thanks a ton.

  6. #6

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    187
    Yes, it's worth mentioning to others that using the NSURLConnection class in a synchronous mode, will
    freeze the client application until the connection completes it's data transfer.
    So if you need to make sure your app can continue to update it's UI, then use the NSURLConnection class
    in a asynchronous mode.

    Great to here you got things working.

    Regards Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. outlook 2011 problem problem problem
    By knfall97 in forum OS X - Apps and Games
    Replies: 0
    Last Post: 03-13-2011, 12:16 AM
  2. Replies: 4
    Last Post: 12-31-2010, 05:19 PM
  3. Replies: 0
    Last Post: 03-08-2010, 08:13 PM
  4. Replies: 7
    Last Post: 09-01-2008, 10:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •