【发布时间】: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