- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifire";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *makingString_fromArray = [appDel.Rhymes_Array objectAtIndex:indexPath.row];
NSArray *datatwoParts_Array = [makingString_fromArray componentsSeparatedByString:@"@"];
cell.textLabel.text = [datatwoParts_Array objectAtIndex:0];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textAlignment = NSTextAlignmentLeft;
// Assign our own background image for the cell
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
return cell;
}
在我的tableview中,只有第一个单元格数据显示,其他空单元格。也是NSLog数组,数据在每个索引上但不在单元格中显示。 只有第一个细胞数据显示。感谢您的帮助
答案 0 :(得分:3)
确保将计数返回为
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [datatwoParts_Array count];
}
同时更改以下代码行
cell.textLabel.text = [datatwoParts_Array objectAtIndex:0];
作为
cell.textLabel.text = [datatwoParts_Array objectAtIndex:indexPath.row];
修改强>
你的代码有点混乱,你想在这里实现什么?
NSString *makingString_fromArray = [appDel.Rhymes_Array objectAtIndex:indexPath.row];
NSArray *datatwoParts_Array = [makingString_fromArray componentsSeparatedByString:@"@"];
另请分享您的tableView:numberOfRowsInSection:
方法
答案 1 :(得分:1)
检查你的
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([datatwoParts_Array count]!=0)
return [datatwoParts_Array count];
return 0;
}
答案 2 :(得分:0)
谢谢大家。 问题是我在Stringpath中得到了\ r \ n,这就是为什么第一个单元格以外的文本没有显示的原因。 我使用NSCharacterset从字符串中删除未使用的字符。
答案 3 :(得分:0)
我在我的项目中发现的同样的问题和我创建的这个表方法试试这个
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
cell.layer.backgroundColor = (__bridge CGColorRef)([UIColor clearColor]);//optional
cell.backgroundView = nil;
}
答案 4 :(得分:0)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [datatwoParts_Array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.text = [datatwoParts_Array objectAtIndex:indexPath.row];
NSLog(@" check the array value ======== %@",[datatwoParts_Array objectAtIndex:indexPath.row]);
}
答案 5 :(得分:0)
这适用于6.1 beta。
cell?.textLabel?.text = [datatwoParts_Array objectAtIndex:0]