Home > iPad, iPhone, Objective-C > Lazy loading Custom UITableViewCell

Lazy loading Custom UITableViewCell

this tutorial says how to lazy load or Asynchronous load custom table cell image so the scrolling of table cell is efficient.i have taken help from ¬†apple’s sample code for lazy loading or asynchronous loading and use for custom table cell.
first crate view controller and create table view as the way you want, i have created view controller and added table view.Now in view controller ,since we are requesting to url for our data ,make NSURLConnection as below

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:xmlDataUrl]];
self.connection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];

since we have set delegate of connection to self to it will return to following method after data is loaded.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.connection = nil;   // release our connection
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 
// create the queue to run our ParseOperation
self.queue = [[NSOperationQueue alloc] init];
ParseOperation *operation = [[ParseOperation alloc] initWithData:self.xmlData delegate:self];
[queue addOperation:operation]; // this will start the "ParseOperation"
[operation release];
self.xmlData = nil;
 
}

in delegate method create NSOperation and parse the xml in operation
After parsing is completed populate the table view.
since main work here is loading the image in table cell
dowloading the image is the same using NSURLConnection and calling appropriate method delegate method after image data is received.
the code can be downloaded from link below
LazyLoadTableImages in custom cell

Categories: iPad, iPhone, Objective-C
  1. sree
    January 11th, 2012 at 14:47 | #1

    i think this isw nice tutorial, how to use for json parsing.plz help me

  2. mohan
    April 19th, 2012 at 20:57 | #2

    same for me need for json parsing

  3. May 25th, 2012 at 15:32 | #3

    Excellent help …..

  4. Nhat Dinh Van
    July 10th, 2012 at 09:39 | #4

    @sree , @mohan i ‘ve installed lazy loading with json parsing in xcode 4.3.3 and ios simulator 5.1
    Hope this help you.
    http://www.mediafire.com/?dotaxuzk7l8wjyb

  5. Randeep
    March 26th, 2013 at 15:49 | #5

    @Nhat Dinh Van I am trying to use your code, it is giving this error “no visible @interface for SBJsonParser declares the selector’objectWithString:error:’”.Please help.

  1. No trackbacks yet.