2015-02-06 16 views
0

호출하는 UITableView numberOfRowsInSection입니다. 그러나 cellForRowAtIndexPath는 호출되지 않습니다. cellForRowAtIndexPath가 호출되지 않은 이유를 모르겠습니다. 제가 iOS UITableView cellForRowAtIndexPath Not Calling

return [array count]+1; 
if (allOfficedata.count >0) return [allOfficedata count] + 1; 

가 cellforrowatindexpath 호출되지

return (allOfficedata.count >0)? allOfficedata.count + 1 : allOfficedata.count; 

또는

부에 열의 번호를 retun 만약 대가 배열 주면 카운트; 또는 11을 반환; 그 작업을 잘 BELOVE 내가 인해 캐치되지 않는 예외 'NSRangeException'응용 프로그램 종료, 이유는 내 코드, 오류

***** 첨부 : '* - [__ NSArrayM objectAtIndex :] : 범위를 넘는 인덱스 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)[email protected]"CellCalloutbox_Office_iPad":@"CellCalloutbox_Office_iPhone"; 

       } 
       else if ([calloutOffice.is_empty_onboarding_mission isEqualToString:@"false"]) 
       { 
        nibName = (isPad)[email protected]"CellCallOutBox_Onboarding_iPad":@"CellCallOutBox_Onboarding_iPhone"; 
       } 
       else if ([calloutOffice.is_empty_community_mission isEqualToString:@"false"]) 
       { 
        nibName = (isPad)[email protected]"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])[email protected]"CellWithImage_Comment_iPad":@"Cell_WithImage_MyOffice_iPad"); 
       NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])[email protected]"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])[email protected]"Cell_withoutImage_withcomment_iPad":@"Cell_withoutImage_Ipad_Office"); 
       NSString *nibNmaeForiPhone = (([fmodel.feedCommentCount integerValue])[email protected]"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; 
      } 
     } 
    } 
} 
+0

'numberOfRowsInSection'에서 반환 된 값을 확인하십시오. –

+0

돌아 오는 중 return [allOfficedata count] +1; 같은 문제 –

+0

'[allOfficedata count] + 1'의 값이 뭔지 전혀 모르겠다. 어떻게 알 수 있을까? –

답변

2

그래서 말을 allOfficedata + numberOfRowsInSection 1 만 heightForRowAtIndexPath에 : 이것은 당신의 CRA가 발생

Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row]; 

: 다음 줄이 마지막 셀에 sh를 넣으십시오. 그래서 마지막 셀인지 확인하고 싶다면 다른 셀을 선택하십시오.

편집 :

뿐만 아니라 (indexPath == 0)하지만 다음 셀에 대한 그 후 당신이 얻을 경우

당신이 뭔가를 할, 당신은 cellForIndexPath에서 비슷한 일을하는 것처럼 보인다 같은 :

Feedmodel *fmodel=[allOfficedata objectAtIndex:indexPath.row]; 

indexPath.row에서 1을 가져와야합니다. 현재 indexage.row == 1, 인덱스 1에있는 객체를 묻는 질문을 할 수 있습니다. 마지막 셀에 도달하면 앱이 위의 라인에서 충돌합니다.

편집 2 :

그래서 문제가 당신은 당신이 말할 때 행에 대해,이 allOfficedata + 1은 아니고, 인덱스 allOfficedata을 요구하고는 테이블의 마지막 셀의 heightForRowAtIndexPath에 도달 할 때 numberOfRowsInSection에서 지정한 +1을 찾기 때문에 거기에없는 색인에 대한 allOfficedata에서 데이터를 요청합니다.

따라서 allOfficedata의 수는 10 (색인 0-9)이고 테이블의 행 수는 allOfficedata + 1이므로 11 (인덱스 0-10)입니다.

이제 heightForRowAtIndexPath에서 마지막 셀 (인덱스 10)을 얻습니다. 인덱스가 0-9이기 때문에 allOfficedata에없는 것입니다. 당신은 allOfficedata에게 인덱스 10을 요청합니다. 충돌 할 것입니다.

+0

자세한 정보를 알려 줄 수 있습니까? –

+0

그 cellforrowatindexpath를 호출하지 않습니다. –

+0

나는 조금 더 많은 예제를 시도했다. 그 전에는 heightForRowAtIndexPath에서 충돌하기 때문에 cellAtIndexPath에 도달하지 못합니다. – BooRanger

0

NSArray은 범위를 벗어납니다.테이블 색인

  • 도 있으므로 동일한 0-9 [하지 1 ~ 10]
  • 이다 하지 1~10] 9 어레이 0

    • 값 10 indexpath.row은 올바른 위치의 배열에서 값을 결정하기위한 올바른 값을 제공합니다.

    +0

    이 물건을 확인했습니다. 그 동안 값을 반환하는 동안 오류가 발생합니다. 내가 수동으로 리턴 11을 주었다면, NSArray.count + 1을 리턴한다. 그 오류를 나타내는 ist를 의미합니다. ** cheyyan 도움이 문제를 해결할 수 있도록 도와주세요 ** ** –

    0

    cellForRowAtIndexPath가 호출되지 않는 가장 큰 이유는, 행 개수가 틀린 것 외에는 테이블 뷰에 표시 할 행이 없다고 생각한다는 것입니다.

    cellForRowAtIndexPath는 셀이 필요할 때만 호출됩니다. 당신은 당신의 코드를 보는 매우 큰 높이의 세포를 가진 것처럼 보입니다. 섹션 헤더보기 또는 높이에 대한 코드를 볼 수 없습니다.

    큰 높이가 주어 졌을 때, 특히 행 0의 경우 (코드에 따라 300 또는 400), 스크롤 업하지 않으면이 함수에 대한 호출이 많지 않습니다. 스크롤 할 때 더 많은 셀 호출이 표시되어야합니다.

    또한 높이를 0으로 돌려 주는지 확인하십시오. 높이가 0이면 그 셀이 보이지 않을 것으로 생각하는 셀을 표시하지 않을 수도 있습니다.

    각 행의 높이에 필요한 스크롤 막대 크기를 예측합니다.