UIActivityIndicator problem

Discussion in 'iOS Programming' started by sagarshivam, Mar 17, 2012.

  1. sagarshivam, Mar 17, 2012
    Last edited by a moderator: Mar 17, 2012

    sagarshivam macrumors member

    May 24, 2011
    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];
                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!!
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Don't use sendSynchronousRequest: Instead use one of the asynchronous request methods. There are several reasons for this but it's impossible to show any progress if you use the synchronous method.
  3. sagarshivam thread starter macrumors member

    May 24, 2011
    Thanks a ton!!

    Changing it to asynchronous solved my problem immediately.

Share This Page