【问题标题】:UITableview grouped style only showing one value from array?UITableview 分组样式仅显示数组中的一个值?
【发布时间】:2013-04-27 11:06:10
【问题描述】:

我的 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;
}

【问题讨论】:

  • if (cell == nil) 的右大括号在哪里?
  • 那个小错误我忘记在此处添加大括号..在代码中
  • 他确实在 8 分钟前编辑了它。它在单元格分配行末尾的; 之后。
  • XIB/Storyboard 中的 tableview 是否足够大以显示 4 行?
  • 是的。它更大。但不显示

标签: ios objective-c uitableview nsarray


【解决方案1】:

您的代码对我来说看起来不错,我认为艾米影响您看到的结果的唯一原因是您如何设置表格视图。
确保您的表格视图框架有足够的错误以显示 4 个项目,并确保您设置了表格视图数据源。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多