Friday, 28 October 2016

Image background service

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"image url"]];

    cell.image = [UIImage imageWithData: imageData];

change to

dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"image url"]];
        if ( data == nil )
            return;
        dispatch_async(dispatch_get_main_queue(), ^{
            // WARNING: is the cell still using the same data by this point??
            cell.image = [UIImage imageWithData: data];
        });
    });

Wednesday, 26 October 2016

Reload particular row and section

Row:  

[self.tablename beginUpdates];
 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
 NSArray *indexPaths = [[NSArray allocinitWithObjects:indexPath, nil];
[self.tablename reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];

 [self.tablename endUpdates];

         (OR)

// Build the two index paths
[self.tablename beginUpdates];
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:3 inSection:2];
NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:4 inSection:3];
// Add them in an index path array
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2, nil];
// Launch reload for the two index path

[self.tablename reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
 [self.tablename endUpdates];


Section:

[self.tablename beginUpdates];
[self.tablename reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
[self.tablename endUpdates];

                (OR)

 [self.tablename beginUpdates];
 NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:self.tablename]);
 NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range];
 [self.tablename reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];
 [self.tablename endUpdates];