0

I have TableView and I want to set different images for every cells. Now I see same image for every cells

Here is my code :

@implementation SecondViewController

{
 NSArray *tableData;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
     tableData = [NSArray arrayWithObjects:@"Restore Edilen Evler", @"Sakarya Kenarı", @"Tekke Seyir Tepesi", @"Kilise",@"Akkaya Şelalesi",@"Kaplıcalar",nil];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
    cell.textLabel.numberOfLines = 2;

if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:@"aktivite4.png"]; 

    return cell;
}
@end

1 Answer 1

0

You need to get the image name based on the cell's indexPath. Update your tableData to include the image name, for example. Then you get the image name much like you get the cell's text. This can be accomplished by changing tableData to a an array of dictionaries where each dictionary has the text and the image name.

2
  • Is it?UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; Nov 7, 2013 at 19:51
  • No. The line that creates the cell doesn't change. The line where you set the image needs to change.
    – rmaddy
    Nov 7, 2013 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.