是UITableView numberOfRowsInSection不打电话。但是cellForRowAtIndexPath并没有被调用。我不明白为什么不调用cellForRowAtIndexPath。如果我更改区段中的行数
 return (allOfficedata.count >0)? allOfficedata.count + 1 : allOfficedata.count; 或
return [array count]+1;  
 if (allOfficedata.count >0) return [allOfficedata count] + 1;如果我给出返回数组计数,或者返回11,则不会调用cellforrowatindexpath;它的工作良好--我附加了代码Error
*由于非正常异常“NSRangeException”终止应用程序,原因:'* -__NSArrayM objectAtIndex::index 10超出界限0。9'
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==self.LeftMenuTable)
        return leftOptions.count;
    return [allOfficedata count]+1;
}
**********************************************************************
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==self.LeftMenuTable)
        return 60;
    Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];
    NSString  *checkType =  fmodel.achievementType;
    if (isPad)
    {
        if (indexPath.row == 0)
        {
            return (isPad)?300.0:434.0;
        }
        else if (indexPath.row == allOfficedata.count+1)
          {return 30.0;}
        else{
        if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
            return ([fmodel.feedCommentCount integerValue] > 0)?366:318;
        else
            return  ([fmodel.feedCommentCount integerValue] > 0)?249:200;
        }
        return 0.0;
    }
    else
    {
        if (indexPath.row == 0)
        {
            return (isPad)?232.0:434.0;
        }
        else
        {
            if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
                return ([fmodel.feedCommentCount integerValue] )?259:222;
            else
                return  ([fmodel.feedCommentCount integerValue])?184:142;
        }
        return 0.0;
    }
}
***************************************************************
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier3 = @"loadMore";
    static NSString *CellIdentifier = @"TableViewCell";
    if (tableView==self.LeftMenuTable)
    {
        TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
            UIView *sepView=[[UIView alloc ]initWithFrame:CGRectMake(0,59, 250, 1)];
            [cell.contentView addSubview:sepView];
            [sepView setBackgroundColor:[UIColor grayColor]];
        }
        cell.cellTextLabel.textColor=[UIColor whiteColor];
        [cell.cellTextLabel setText:[[leftOptions objectAtIndex:indexPath.row] valueForKey:@"name"]];
        [cell.CellImageView setImage:[UIImage imageNamed:[[leftOptions objectAtIndex:indexPath.row] valueForKey:@"image"]]];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor clearColor];
        return cell;
    }
    else
    {
        NSUInteger row = [indexPath row];
        NSInteger countRoe = [allOfficedata count];
          if (row == countRoe )
          {
              UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier3];
              if (cell == nil) {
                  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier3];
              }
              cell.textLabel.text = @"LoadMore";
              return cell;
          }else
         {
             if (indexPath.row == 0)
             {
                 //CellCallOutBox_Onboarding_iPad
                 //CellCalloutbox_Office_iPad
                 //CellCalloutbox_Office_iPhone
                 NSString *nibName;
                 if ([calloutOffice.is_empty_daily_mission isEqualToString:@"false"]) {
                     nibName = (isPad)?@"CellCalloutbox_Office_iPad":@"CellCalloutbox_Office_iPhone";
                 }
                 else if ([calloutOffice.is_empty_onboarding_mission isEqualToString:@"false"])
                 {
                     nibName = (isPad)?@"CellCallOutBox_Onboarding_iPad":@"CellCallOutBox_Onboarding_iPhone";
                 }
                 else if ([calloutOffice.is_empty_community_mission isEqualToString:@"false"])
                 {
                     nibName = (isPad)?@"CellCallOutBox_Onboarding_iPad":@"CellCallOutBox_Onboarding_iPhone";
                 }
                 CellCalloutbox_Office *cellcallout = (CellCalloutbox_Office *)[tableView dequeueReusableCellWithIdentifier:nibName];
                 if (cellcallout == nil)
                 {
                     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
                     cellcallout = [nib objectAtIndex:0];
                 }
                 cellcallout.aMissionDelegate = self;
                 [cellcallout.btnVideoOfTheDay addTarget:self action:@selector(videoOfTheDay) forControlEvents:UIControlEventTouchUpInside];
                 cellcallout.backgroundColor=[UIColor clearColor];
                 [cellcallout setArraywithCallOut:calloutOffice expanded:isCallOutOfficeExpanded];
                 [cellcallout.btnBackCallout addTarget:self action:@selector(calloutBack) forControlEvents:UIControlEventTouchUpInside];
                 [cellcallout.btnDailyMission addTarget:self action:@selector(openCalloutDilyMission) forControlEvents:UIControlEventTouchUpInside];
                 return cellcallout;
             }
             Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row];
             NSString  *checkType =  fmodel.achievementType;
             if (![checkType isEqualToString:@""] || [checkType isEqualToString:@"0"] || [checkType isEqualToString:@"1"])
             {
                 static NSString *simpleTableIdentifier = @"CellWithImageVideo";
                 CellWithImageVideo *cell = (CellWithImageVideo *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
                 NSString *nibNmaeForiPad = (([fmodel.feedCommentCount integerValue])?@"CellWithImage_Comment_iPad":@"Cell_WithImage_MyOffice_iPad");
                 NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])?@"CellWithImagewithComment_iPhone":@"CellWithImageVideo");
                 if (cell == nil)
                 {
                     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:(isPad)?nibNmaeForiPad:nibNmaeForiPhone owner:self options:nil];
                     cell = [nib objectAtIndex:0];
                 }
                 cell.backgroundColor=[UIColor clearColor];
                 cell.contentView.backgroundColor=[UIColor clearColor];
                 [cell setFeeddata:fmodel indexPath:indexPath];
                 [cell.hifiveBtn         addTarget:self action:@selector(hifiveClickedMyOfiice:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.playMintBtn       addTarget:self action:@selector(getFeedDetails:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.planToDoBtn       addTarget:self action:@selector(planToDoClickedOffice:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.userImageBtn      addTarget:self action:@selector(gotouserProfile:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.inspireBtn        addTarget:self action:@selector(InspireClicked:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.sendCommentBtn    addTarget:self action:@selector(serverCommentPost:) forControlEvents:UIControlEventTouchUpInside];
                 [cell.btnCompliment     addTarget:self action:@selector(getFeedCommentPopup:) forControlEvents:UIControlEventTouchUpInside];
                 cell.txtFldCommentField.delegate  = self;
                 return  cell;
             }
             else
             {
                 static NSString *simpleTableIdentifier = @"CellWithoutImage";
                 NSString *nibNmaeForiPad = (([fmodel.feedCommentCount integerValue])?@"Cell_withoutImage_withcomment_iPad":@"Cell_withoutImage_Ipad_Office");
                 NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])?@"CellWithoutImagewithComment_iPhone":@"CellWithoutImage");
                 CellWithoutImage *cell = (CellWithoutImage *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
                 if (cell == nil)
                 {
                     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:(isPad)?nibNmaeForiPad:nibNmaeForiPhone owner:self options:nil];
                     cell = [nib objectAtIndex:0];
                 }
                 [cell setFeeddata:fmodel indexPath:indexPath];
                 cell.backgroundColor=[UIColor clearColor];
                 cell.contentView.backgroundColor=[UIColor clearColor];
                 [cell.hifiveBtn         addTarget:self action:@selector(hifiveClickedMyOfiice:)           forControlEvents:UIControlEventTouchUpInside];
                 [cell.planToDoBtn       addTarget:self action:@selector(planToDoClickedOffice:)           forControlEvents:UIControlEventTouchUpInside];
                 [cell.userImageBtn      addTarget:self action:@selector(gotouserProfile:)                 forControlEvents:UIControlEventTouchUpInside];
                 [cell.inspireBtn        addTarget:self action:@selector(InspireClicked:)                  forControlEvents:UIControlEventTouchUpInside];
                 [cell.btnCompliment     addTarget:self action:@selector(getFeedCommentPopup:)                   forControlEvents:UIControlEventTouchUpInside];
                 [cell.sendCommentBtn     addTarget:self action:@selector(serverCommentPost:)               forControlEvents:UIControlEventTouchUpInside];
                 [cell.btnTextMintTapped    addTarget:self action:@selector(getFeedDetails:)               forControlEvents:UIControlEventTouchUpInside];
                 cell.txtFldComment.delegate = self;
                 return cell;
             }
         }
    }
}发布于 2015-02-06 14:14:02
除了行计数错误之外,cellForRowAtIndexPath从未被调用的最可能的原因是表视图认为没有要显示的行。
只有在需要单元格时才会调用cellForRowAtIndexPath。您的代码中似乎有高度非常高的单元格。无法看到任何用于区段标题视图或高度的代码。
因此,考虑到很大的高度,特别是对于第0行(根据您的代码是300或400 ),除非您向上滚动,否则不会有对此函数的多次调用。滚动时,应该会看到更多对单元格的调用。
还要检查你是否返回0的高度,因为这也可以阻止它试图显示的细胞,我认为,因为它不会被看到。
它将要求每一行的高度来估计所需的滚动条大小。
https://stackoverflow.com/questions/28366906
复制相似问题