【发布时间】:2013-12-30 07:17:29
【问题描述】:
在我的应用程序中,我创建了一个名为“array”的可变数组。
array=[[NSMutableArray alloc]initWithObjects:@"a",@"b",@"c",@"d",@"e", nil];
我的 tableView 只包含一个多节的一行,每个节都有一个 customView 只包含一个标签。
我的自定义视图名称是 ContentOfCell
ContentOfCell * contentOfCell=[[ContentOfCell alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
[cell.contentView addSubview:contentOfCell];
我已将数组添加到标签中
contentOfCell.label.text=[array objectAtIndex:indexPath.section];
我的问题是它只识别数组中的前 4 个值,并且前 4 个值在部分中重复
我觉得这里出了点问题
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [indexPath row]+50;
}
如果我将 50 更改为 100,如果没有正确插入值,则会发生错误
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentifier=[NSString stringWithFormat:@"MyTableView"];
cell=[myTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell== nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
ContentOfCell * contentOfCell=[[ContentOfCell alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
[cell.contentView addSubview:contentOfCell];
contentOfCell.nameField.text=[arr objectAtIndex:indexPath.section];
cell.contentView.backgroundColor=[UIColor whiteColor];
}}
这里的视图只包含 3 行,当我向下滚动时再次启动数组,然后再次打印值
【问题讨论】:
-
你能显示tableview方法的代码吗?
-
确保 numberOfSectionsInTableView 将等于数组计数
-
是的,在 numberOfSection 委托中我已经给出了 return[array count];
-
显示你的代码
cellForRowAtIndexpath?我认为,dequeueReusable中的错误 -
显示 cellForRowAtIndexpath 的代码
标签: ios uitableview uiview nsmutablearray uilabel