Reputation: 151
How to set a different image for each cell of my table view. i want to do it through array of image names
Upvotes: 2
Views: 968
Reputation: 2218
Your solution is here go to this link How to add UIImage in the UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"TableView";
MainView *cell = (MainView *)[tableView dequeueReusableCellWithIdentifier: MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil];
cell = tableCell;
}
[cell LabelText:[arryList objectAtIndex:indexPath.row]];
[cell ProductImage:[imagesList objectAtIndex:indexPath.row]];
return cell;
}
Uitableview with image shows like
Upvotes: 5
Reputation: 720
for example:
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%i.png", indexPath.row]];
or
cell.imageView.image = (UIImage *)[yourArray objectAtIndex:indexPath.row];
Upvotes: 5
Reputation: 7461
Use following code...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Initialise the cell */
static NSString *CellIdentifier = @"MyTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
/* Configure the cell */
NSString *cellImageName = [[self cellImageNames] objectAtIndex:[indexPath row]];//cellImageNames ism image names array where
UIImage *cellImage = [UIImage cellImageName];
[[cell imageView] setImage:cellIcon];
// Other cell configuration code...
return cell;
}
Hope, this will help you...
Upvotes: 6