Ios 每次显示索引0的indexath.row

Ios 每次显示索引0的indexath.row,ios,uitableview,row,nsindexpath,Ios,Uitableview,Row,Nsindexpath,所以问题是,在我的cellForRowAtIndexPath方法中,每次indexpath.row仅为“0”。为了确认我已经在计数器上打印了“计数”。但每次它显示0时,我的整个表都被分配了相同的值。不知道怎么了。请找个人帮忙 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [arr_Max count]; } - (NSInteger)tableView:(UITableView *)

所以问题是,在我的cellForRowAtIndexPath方法中,每次indexpath.row仅为“0”。为了确认我已经在计数器上打印了“计数”。但每次它显示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;
}

您的tableView委托方法
numberOfRowsInSection
很可能返回了错误的行数

确保此委托方法是必需的

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

正在返回一个有效的数字-通常是数据源中的元素数。

似乎您的数字或行数=1(来自numberOfRowsInSection)。 因此,每次当tableview委托激发方法时,它只返回1行。 你能解释一下你的问题吗

根据我的理解,你应该继续这样做

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: 
(NSInteger)section
{
return [arr_Max count];
} 
然后可能会根据数组内容获得计数值。
如果可以或有任何关于此的疑问,请发表意见。

您已使用以下内容更新代码,其他部分将保持不变:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arr_Max count];
}

您的代码是错误的,正确的代码如下:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section
{
    return [arr_Max count];
}

您是如何实现numberOfRowsInSection的?请提供更多代码以了解您的问题。请检查我的编辑version@Rahul您是如何定义计数变量的?您是否在代码中的任何地方对其进行了初始化?@Rahul您已经为行计数返回了计数修复1,然后您只能获得一个带有0的索引。我之所以采用这种方式,是因为我想获得单元格之间的空间。请为这种情况向我提出适当的解决方案。@Rahul如果您需要单元格之间的空间,那么您可以在SimpleTableViewCell视图的底部增加一些空间。我想这是因为在“numberOfRowsInSection”中只返回1。我实现这种方法是因为我想在单元格之间获得空间。请为这种情况向我提出适当的解决办法。检查我编辑的版本