CraigBellamy
CraigBellamy

Reputation: 27

Array only repeats first item with other array

The self.tablePicture array only seems to repeat the first item "star_white.png" the other colours etc with the self.tableData array and cannot understand why... any ideas why?

- (id)init
{
self = [super init];
if (self) {
    // Custom initialization
    self.tableData = [NSArray arrayWithObjects:@"continent", @"region", @"country", @"city", @"town", @"district", @"borough", nil];
    self.tablePicture = [NSArray arrayWithObjects:@"star_white.png", @"star_blue.png", @"star_red.png", @"star_green.png", @"star_purple.png", @"star_orange.png", @"star_black.png", nil];
    CGRect frame = self.view.bounds;
    frame.size.height -= 100;
    self.tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
    [self.tableView setBackgroundColor:[UIColor clearColor]];
    [self.tableView setDataSource:self];
    [self.tableView setDelegate:self];
    [self.tableView setScrollEnabled:NO];

    [self.view addSubview:self.tableView]; 
}
return self;
}

and

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}

// modify cell
NSString *name = [self.tableData objectAtIndex:indexPath.section];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
[cell.textLabel setText:name];
cell.imageView.image = [UIImage imageNamed:[tablePicture objectAtIndex:indexPath.row]];
cell.backgroundColor = [UIColor clearColor];

return cell;
}

Upvotes: 0

Views: 71

Answers (1)

Jaybit
Jaybit

Reputation: 1864

They are all in section 0.

NSString *name = [self.tableData objectAtIndex:indexPath.section];

Try

NSString *name = [self.tableData objectAtIndex:indexPath.row];

Upvotes: 1

Related Questions