2011-03-04 2 views
0

이것은 나를 미치게합니다! 이 오류로 계속 충돌합니다. 아래는 제 코드입니다. 내 UITabelView에 "25 개 이상의"기능을 추가 셀을 넣으려고합니다. 하지만 아래 heightForRowAtIndexPath 함수의 아래 충돌합니다. 나는 무엇을 간과하고 있는가?iPhone : 경계선 이상 [0 .. 8] '

TIA.

[NSMutableArray를 objectAtIndex :] 인덱스 범위를 넘는 4294967295 [0 .. 8]

0 CoreFoundation에서
0x01338be9 __exceptionPreprocess + 185 1 libobjc.A.dylib
0x0148d5c2 objc_exception_throw + 47 2 CoreFoundation에서
0x0132e6e5 - [__ NSArrayM objectAtIndex :] + 261 3
mackdabMobile
0x00004f56 - [AllmackTableViewController있는 tableView : heightForRowAtIndexPath :] +

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
    { 
     NSLog(@"IndexRow int: %i", indexPath.row); 
     NSLog(@"postsArray count: %i", [postsArray count]); 
     if(indexPath.row < [postsArray count]){ **<----Where it crashes** 
      Post *myPost = [postsArray objectAtIndex:[indexPath row] - 1]; 
      NSString *text = myPost.description; 

      CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 88.0f); 

      CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 

      CGFloat height = MAX(size.height, 35.0f); 

      return height + (CELL_CONTENT_MARGIN * 2) + 28.0f; 
     }else{ 
      return 100.0f; 
     } 


    } 

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


     // Return 1 section which will be used to display the giant blank UITableViewCell as defined 
     // in the tableView:cellForRowAtIndexPath: method below 
     if ([self.postsArray count] == 0){ 

      return 1; 

     } else if ([self.postsArray count] < 25) { //self.webServiceDataModel.total 

      // Add an object to the end of the array for the "Load more..." table cell. 
      NSLog(@"postsArray count: %i", [postsArray count]); 
      return [self.postsArray count] + 1; 
      NSLog(@"postsArray count after +1: %i", [postsArray count]); 

     } 
     // Return the number of rows as there are in the postsArray Post data is empty. 
     return [self.postsArray count]; 

    } 

답변

5

[indexPath row] - 1가 문제가 될 것이다 indexpath.row -1 = 0 용

이다.

[array objectAtIndex:-1]은 예외입니다. 따라서 충돌이 발생합니다.

1

indexPath.row이 0 일 때 배열에서 색인 -1의 항목을 가져 오려고합니다 ...