Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2011 15:41
Show Gist options
  • Save anonymous/1242530 to your computer and use it in GitHub Desktop.
Save anonymous/1242530 to your computer and use it in GitHub Desktop.
cell using nib
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = self.tvc;
}
UILabel* lab = (UILabel*)[cell viewWithTag: 2];
// ... set up lab here ...
// notice how much less of this there now is, because it's mostly done in the nib
lab.text = @"label";
UIImageView* iv = (UIImageView*)[cell viewWithTag: 1];
// ... set up iv here ...
UIImage* im = [UIImage imageNamed:@"image.png"];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(35,35), YES, 0.0);
[im drawInRect:CGRectMake(0,0,35,35)];
UIImage* im2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
iv.image = im2;
iv.contentMode = UIViewContentModeCenter;
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment