Cyph3r Cyph3r - 1 year ago 88
iOS Question

Image in the Tableview cell

Hi i am a newbie to iOS.

I have implemented a tableview in ViewController1.In the tableview i am displaying tittle,detailText and disclosure indicator for the cell.

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *MyIdentifier = @"MyIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1

cell.textLabel.text =[listTableArray objectAtIndex:indexPath.row];
cell.textLabel.textColor=[UIColor grayColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


return cell;

Everything works fine,Now i need a image before the disclosure indicator when i do it with

UIImageView *accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
accessoryView.image=[UIImage imageNamed:@"list.png"];
cell.accessoryView = accessoryView;

Disclosure indicator is replaced by the image.But i need both image along with disclosure indicator without using Custom cell.

How can i do it...? Help me out.


enter image description here

similiar to the due date but at the place of time i need image

Answer Source

UITableViewCell have a fixed layout, depending on the style you use when you initialize it. You cannot change that layout, since the cell lays out its subviews as it prefers to have them.

add the - (void)layoutSubviews to your cell subclass like this:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0.0f , 0.0f, 20.0f, 20.0f);

else try this

 UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"list.png"];;
[imageView setFrame:CGRectMake(50, 5, 20, 20)]; // customize the frame
 [cell.contentView addSubview:imageView];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download