【发布时间】:2015-01-24 10:52:16
【问题描述】:
所以问题是,在我的 cellForRowAtIndexPath 方法中,每次 indexpath.row 仅为“0”。并确认我已经用“count”打印了计数器。但每次它显示 0 并且我的整个表都分配有相同的值。不知道怎么了。请有人帮忙。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [arr_Max count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableViewCell";
count=(int)indexPath.row;
NSLog(@"%d",count);
SimpleTableViewCell *cell = (SimpleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.label.text=[NSString stringWithFormat:@"%@",[arr_Max objectAtIndex:count] ];
return cell;
}
【问题讨论】:
-
你们是如何实现 numberOfRowsInSection 的?
-
请提供更多代码以了解您的问题。
-
检查我编辑的版本
-
@Rahul 你是如何定义计数变量的?您是否在代码中的任何位置对其进行了初始化?
-
@Rahul 你已经返回 count fix 1 作为行数,那么你只能得到一个 0 的索引。
标签: ios uitableview row nsindexpath