0

Since 2009, this is the way I populate tableView cells (custom cell):

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AccountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountCellID"]; if (cell==nil) { cell = [[AccountTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AccountCellID"]; } // here update content cell.customImg = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]] return cell; } 

Is this good or are there better ways? Some people said I should update everything in the TableViewcell custom class itself. Is there any difference?

1 Answer 1

1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return Array.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ FilterTableViewCell *cell = (FilterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"filter cell"]; BrandObjectClass *brandObject = [brandsArray objectAtIndex:indexPath.row]; cell.lblFilterName.text = brandObject.brandName; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.lblFilterName.font = [UIFont fontWithName:@"Roboto-Medium" size:cell.lblFilterName.font.pointSize]; cell.imgTick.hidden = NO; return cell; } 

When you are working with custom table view cell the casting is also important because dequeueReusableCellWithIdentifier returns object of UITableViewCell.

Hope this will help.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks good point on that casting. But how about the cell data population? Does it matter if we do it in cellForRow or in the cell's custom class itself (ie in CustomCell.m/h.) ?
Well if you do it in the cell's custom class then it would be the perfect implementation of MVC structure. I was not on my system so that's why i had made this false case fro your answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.