Why can't scroll table view when downloading

Discussion in 'iOS Programming' started by mikezang, Dec 22, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I am using a table view and download data using performSelectorInBackground, but I found I can scroll table view when I download, what can I do?
    Thanks for your suggestion.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Post your code. It sounds like you are blocking the main thread.
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    I have a table view controller as below:
    Code:
    @interface MasterTableViewController : UITableViewController {
        MonthData *monthData;
    	
        DetailViewController *detailViewController;
    }
    The MonthData class as below
    Code:
    @interface MonthData : NSObject <NewerFileDownloadDelegate> {
        NSArray *allData;
        NewerFileDownload *download;
    }
    
    - (void)downloadData {
        [download start];
    }
    
    The class NewerFileDownload is a wrapper class for ASINetworkQueue/ASIHttpRequest. it looks like as below:
    Code:
    @interface NewerFileDownload : NSObject {
        ASINetworkQueue *networkQueue;
        ASIHTTPRequest *request;
    	
        id delegate;
    }
    
    - (void)start {
        request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:fileName]];
    	
        [networkQueue addOperation:request];
        [networkQueue go];
    }
    
    When I click download button, I call code as below:
    Code:
    - (IBAction)download:(id)sender {
        [self performSelectorInBackground:@selector(downloadEvents) withObject:nil];
    }
    
    - (void)downloadEvents {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        [monthData downloadData];
        [pool release];
    }
     
  4. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #4
    ASIHTTP is already using an operation queue to perform the network request asynchronously; there is no need for you to call this selector on a background thread.
     
  5. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #5
    I knew it, I use it in background because I can't scroll my view when downloading.
     

Share This Page