2014-11-12 1 views
0

] 이것은 현재 받고있는 충돌입니다. 누군가가이 문제를 해결하는 방법을 알아낼 수있게 도와 줄 수 있습니까? 이 줄에서 발생합니다. UITableViewCell* cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]]; indexPath가 유효한지 확인하면 해결할 수 있다고 생각했지만 그렇지 않았습니다. 이 일을 막을 방법이 있습니까? 모든 팁이나 제안을 부탁드립니다. 나는 아래에서 시도한 것을 게시 할 것입니다.iOS : 치명적인 예외 : NSRangeException *** - [__ NSArrayM objectAtIndex :] : 경계 1을 넘어서는 인덱스 1 [

NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:point]; 
if (indexPath) { 
UITableViewCell* cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]]; 
.... rest of my code 
    } 

답변

0

tableView에는 하나 이상의 행이있을 수 있습니다 (또는 없습니까?). 당신이있는 tableView하기 전에이 작업을 실행하는 경우

당신의 오류 메시지가 나타난 바와 같이

, 0

.. 당신이 인덱스 1에서 객체를 참조하려고하고 있지만 배열의 범위가 0 인 것은 '당신이 초기화됩니다 실행 위치를 변경해야하거나 tableView:numberOfRowsInSection: 대리자 메서드를 구현하는 것을 잊었을 수 있습니까? 당신이 당신의 질문이 줄을 오는 그 오류가 말했듯이

0

, 그것은 indexPath가 나는 당신 의심, 일부 참조가

if (indexPath) { 
     UITableViewCell* cell=[_tableView cellForRowAtIndexPath:indexPath]; 
    } 

이 줄

if (indexPath) { 
    UITableViewCell* cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]]; 
} 

을 변경 시도 잡고 그러나 것을 의미한다 테이블 뷰에 두 개 이상의 항목이 없습니다.

2

배열을 초기화하기 전에 테이블보기를 다시로드하거나 배열을 사용할 때 배열이 비어있을 수 있습니다! 사용할 때처럼

: cellForRowAtIndexPath에서

NSString *xyz = [self.your_array objectAtIndex:indexPath.row]; 

는, 늘 당신의 응용 프로그램을 충돌 코드를 fllowing보십시오!

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

static NSString *CellIdentifier = @"xyz_cell"; 
long nodeCount = [self.your_array count]; 

if (nodeCount == 0 && indexPath.row == 0) 
{ 
    Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:CellIdentifier] ; 
     cell.lbl.textAlignment = NSTextAlignmentCenter; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    cell.lbl.text = @"No Posts yet !"; 

    return cell; 
} 


else{ 

Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

if (cell == nil) { 
    cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} // Your Code Goes HERE .... NSString *xyz = [self.your_array objectAtIndex:indexPath.row]; } 

그래서 빈 배열의 경우 키 하나의 값을 찾지 못하고 앱이 다운되지 않습니다!

도움이 되었기를 바랍니다.

관련 문제