Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd images to table cells in sections
    primarykey
    data
    text
    <p>i want to display an image besides the text in table cell. i have 2 sections, General and Assignments. Now i only want to display image beside Assignments and no image besides General section. the below code displays images for Assignments section and then again repeats the images for General section. Can anybody help me how to accompalish this.</p> <p>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad {</p> <pre><code> staffImages = [[NSMutableArray alloc] init]; NSArray *arrTemp1 = [[NSArray alloc] initWithObjects:@"TRANSPORTATION",@"ROOMS",@"ACTIVITIES",nil]; NSArray *arrTemp2 = [[NSArray alloc] initWithObjects:@"CHAT",@"SEARCH",@"CALL",@"MORE",nil]; NSDictionary *temp =[[NSDictionary alloc] initWithObjectsAndKeys:arrTemp1,@"Assignments",arrTemp2, @"General",nil]; //Add item images [staffImages addObject:@"transportation.png"]; [staffImages addObject:@"hotel.png"]; [staffImages addObject:@"activities.png"]; //Set the title self.navigationItem.title = @"STAFF ASSIGNMENTS"; self.tableContents=temp; [temp release]; self.sortedKeys =[self.tableContents allKeys]; [arrTemp1 release]; [arrTemp2 release]; [super viewDidLoad]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease]; } NSUInteger row = [indexPath row]; cell.textLabel.text = [listData objectAtIndex:row]; cell.imageView.image = [UIImage imageNamed:[staffImages objectAtIndex:indexPath.row]]; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload