self.tablePicture数组似乎只用self.tableData数组重复了第一项“star_white.png”其他颜色等,并且无法理解为什么......任何想法为什么?
- (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;
}
和
- (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;
}
答案 0 :(得分:1)
他们都在第0部分。
NSString *name = [self.tableData objectAtIndex:indexPath.section];
尝试
NSString *name = [self.tableData objectAtIndex:indexPath.row];