Viewing a table with a custom cell (programmatically)

So far, I used to create my own cells to make my cell the way I wanted, but this time the height of the cell will change one by one, so I cannot create a fixed cell size.

So, I decided to create it programmatically ... Is the method below a good way to achieve it?

// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; UILabel *pseudoAndDate = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)]; [pseudoAndDate setTag:1]; [cell addSubview:pseudoAndDate]; [pseudoAndDate release]; } CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]]; UILabel *label = (UILabel *)[cell viewWithTag:1]; [label setText:[NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]]; return cell; } 

or .. am I missing something? The reason is not working;)

Thanks,

Gauthier.

+6
uitableview row customization cell reusability
source share
3 answers

New link for custom UITableViewCell programmatically Apple Documentation UITableViewCell

0
source share

Why create a shortcut when you don't need it? Use the label UITableViewCell.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]]; cell.textLabel.text = [NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]; return cell; } 
0
source share
0
source share

All Articles