UITableview分组样式只显示数组中的一个值?

时间:2013-04-27 11:06:11

标签: ios objective-c uitableview nsarray

MY UITableview Group样式仅显示4个元素数组中的一个值。

在viewdidload中我添加以下数组

    _displayThemeItems=[[NSArray alloc]initWithObjects:@"Default",@"Night",@"Sepia" ,@"Blue" ,nil];
    _displayThemeIcons=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"day.png"],[UIImage imageNamed:@"night.png"],[UIImage imageNamed:@"sepia.png"], [UIImage imageNamed:@"blue.png"],nil];

和我的表委托方法

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

      return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

        return [_displayThemeItems count];


}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



    static NSString *CellIdentifier=@"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // No cell available - create one.
    if(cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                           reuseIdentifier:CellIdentifier];}
    NSLog(@"rray%@",_displayThemeItems);
    cell.textLabel.text = [_displayThemeItems objectAtIndex:indexPath.row];
    cell.imageView.image=[_displayThemeIcons objectAtIndex:indexPath.row];

     return cell;
}

2 个答案:

答案 0 :(得分:0)

您的代码对我来说很好,唯一可以让我认为影响结果的唯一原因就是您如何设置表格视图。
确保您的表格视图框架足以显示4个项目,并确保设置了tabe视图数据源。

答案 1 :(得分:0)

在返回之前添加“}”,以便您设置标题和图像的代码位于“if”语句下。