我有一个问题,当我滚动我的表视图数据不是根据数组它显示较旧的单元格数据

时间:2017-04-17 09:33:49

标签: ios objective-c uitableview nsarray

当我滚动UITableView时出现问题,第一次显示两行后,当我滚动到第三行时,它再次显示第三行的第一行数据。

我使用过这段代码:

static NSString *CellIdentifier = @"inviCell1";

        inviProfileCell *cell1 =
        (inviProfileCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell1.selectionStyle = UITableViewCellSelectionStyleNone;

        if(cell1 == nil) {
            cell1 = [[inviProfileCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;

        }

      Obj=[[ObjClass alloc]init];

      Obj=[fetchedArray objectAtIndex:0];

        UIButton *btn1 = (UIButton *)[cell1 viewWithTag:101];
        UIButton *btn2 = (UIButton *)[cell1 viewWithTag:102];
        UIButton *btn3 = (UIButton *)[cell1 viewWithTag:103];
        UIButton *btn4 = (UIButton *)[cell1 viewWithTag:104];
        UIButton *btn5 = (UIButton *)[cell1 viewWithTag:105];
        UIButton *btn6 = (UIButton *)[cell1 viewWithTag:106];

        cell1.moreBtn.tag = indexPath.row+1;
        cell1.moreBtn.userInteractionEnabled = YES;
        if (inviLoadCount > indexPath.row+1) {
            cell1.moreBtn.hidden = YES;
        }else{
            cell1.moreBtn.hidden = NO;
        }

        int maxindex = (int)(6*(indexPath.row+1));
        int startIndex = (int)(6*indexPath.row);
        int counter = 1;

        NSLog(@"%lu",(unsigned long)boast_Obj.purchase_array.count);
        for (int i = startIndex; i < maxindex; i++) {                
       //  functionality....
        }

我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

在您的全班中,UITableView的哪些方法实施并不完全清楚。你应该至少有两个重要的方法:

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


- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath

这也是this on AppCoda

的好教程