I have a tableview with custom cells inside a view controller. My tableview works properly. What I am trying to do is develop the image below programmatically. Where "label" is the text that is custom and changes depending on some input. How can I include these 2 labels (in cellForRowAtIndexPath:) and determine their position in the cell. Image contains 2 different table cells.
I am aware how to do it through storyboard, but I need to do it programmatically cause I am using dynamic cells in xCode 4.5.
The image refers to the index cells 1 and 2. I have only managed to include one text label per cell till now.
- (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];
}
switch ([indexPath row])
{
case 0:
{
// image cell - image resize and centred
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(30,2, 180, 180)];
imv.image=[UIImage imageNamed:@"test1.jpg"];
imv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[cell.contentView addSubview:imv];
imv.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
cell.accessoryType = UITableViewCellAccessoryNone;
break;
}
case 1:
{
cell.textLabel.text = @"Name";
break;
}
case 2:
{
cell.textLabel.text = @"Manufacturer";
break;
}
case 3:
{
cell.textLabel.text = @"Overall Score";
break;
}
case 4:
{
cell.textLabel.text = @"Description";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
break;
}
case 5:
{
cell.textLabel.text = @"Videos";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
break;
}
}
return cell;
}
Thank you in advance