Search code examples
iphonecocoa-touchxcodeipaduitableview

Adding different icons to each cells in table view


I want to add different icons to the table view present in my app.Can anyone guide me through a proper array or if possible show some sample code or example.Any help will be appreciated.

Thanks, Christy


Solution

  • Say the icons are stored as icon0.png, icon1.png and so on in the app bundle. You can give the icon for each cell as

    cell.imageView.image = [UIImage imageNamed:    
                  [NSString stringWithFormat:@"icon%d.png",indexPath.row]];
    

    Swift

        cell.imageView?.image = UIImage(named: "icon\(indexPath.row).png")