CopyPastor

Detecting plagiarism made easy.

Score: 0.7941208481788635; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2015-04-16
by Sanjay Mohnani

Original Post

Original - Posted on 2014-07-02
by Nitesh Borad



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Inside `cellForRowAtIndexPath:` schedule the image and posts to be downloaded on separate thread for each cell, and as the images and posts are downloaded update the corresponding cells with the received data.
For downloading the images and posts You can use lazy loading, also you can asynchronously download your resources using GCD API as-

// sample usage of GCD API - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.imageView.image = nil; // or cell.imageView.image = [UIImage imageNamed:@"placeholder.png"]; dispatch_async(kBgQueue, ^{ // download the image asynchronously as NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://imageurl.com/%@.jpg",[[modal objectAtIndex:indexPath.row] objectForKey:@"imageId"]]]]; if (imgData) { UIImage *image = [UIImage imageWithData:imgData]; if (image) { // when the image is downloaded set it as dispatch_async(dispatch_get_main_queue(), ^{ UITableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath]; if (updateCell) updateCell.imageView.image = image; }); } } }); return cell; }
**Note**: This is a rough idea to do so, you need to use/ implement the same as per your needs.
/* I have done it this way, and also tested it */
Step 1 = Register custom cell class (in case of prototype cell in table) or nib (in case of custom nib for custom cell) for table like this in viewDidLoad method:
[self.yourTableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"CustomCell"];
OR
[self.yourTableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:@"CustomCell"];
Step 2 = Use UITableView's "dequeueReusableCellWithIdentifier: forIndexPath:" method like this (for this, you must register class or nib) :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath]; cell.imageViewCustom.image = nil; // [UIImage imageNamed:@"default.png"]; cell.textLabelCustom.text = @"Hello"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // retrive image on global queue UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:kImgLink]]]; dispatch_async(dispatch_get_main_queue(), ^{ CustomTableViewCell * cell = (CustomTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; // assign cell image on main thread cell.imageViewCustom.image = img; }); }); return cell; }

        
Present in both answers; Present only in the new answer; Present only in the old answer;