我有一个NSMutableArray和一个从NSMutableArray填充的分组表视图。
当我使用NSLog输出打印NSmutableArray时
"String1","String2","String3"
但是在UITableView Cell上我总是看到NSMUtableArray的第一项:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [_presenterList count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSLog(@"_presenterList objectAtIndex: %@",[_presenterList objectAtIndex:indexPath.row]);
cell.textLabel.text=[_presenterList objectAtIndex:indexPath.row];
return cell;
}
输出NSlog "String1"
tableview上的输出
String1
String1
String1
我做错了什么?
编辑屏幕拍摄
我从字符串和1个tableview行创建一些标题,如图所示
答案 0 :(得分:2)
cell.textLabel.text=[_presenterList objectAtIndex:indexPath.section];
而不是
cell.textLabel.text=[_presenterList objectAtIndex:indexPath.row];
答案 1 :(得分:1)
您在numberOfRowsInSection
和[array count]
中numberOfSectionsInTableView
返回“1”。这是向后的(除非你真的想要一个数组中每个项目的部分。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_presenterList count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}