2010-07-25 5 views
0

각 배열에 대해 3 개의 NSArrays와 3 개의 NSDictionaries를 포함하는 UITableView가 있습니다.다중 섹션 UITableView 문제


    - (void)viewDidLoad { 
    [super viewDidLoad]; 
    contentArray = [[NSMutableArray alloc] init]; 

    self.settingsArray = [NSArray arrayWithObjects:@"Settings", nil]; 
    NSDictionary *settingsDict = [NSDictionary dictionaryWithObject:settingsArray forKey:@"Settings"]; 

    self.infoArray = [NSArray arrayWithObjects: @"Version 1.0", @"© Copyrights 2010", @"Developer Site", @"App Page", @"Report a Bug", nil]; 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:infoArray forKey:@"Settings"]; 

    self.contactArray = [NSArray arrayWithObjects: @"Developer Site", @"App Page", @"Report a Bug", nil]; 
    NSDictionary *contactDict = [NSDictionary dictionaryWithObject:contactArray forKey:@"Settings"]; 

    [contentArray addObject:infoDict]; 
    [contentArray addObject:settingsDict]; 
    [contentArray addObject:contactDict]; 
    } 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    if ([[infoArray objectAtIndex:indexPath.row] isEqual:@"Version 1.1"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[infoArray objectAtIndex:indexPath.row] isEqual:@"© Copyrights 2010"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[settingsArray objectAtIndex:indexPath.row] isEqual:@"Settings"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"NULL" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"Developer Site"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"App Page"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"Report a Bug"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES];  
    } 
} 


문제는 내가 당신이 범위를 넘는 인덱스를 액세스 할 때 그 오류가 발생합니다

+0

어떤 오류 메시지가 기록됩니까? – Kurbz

+0

2010-07-25 21 : 58 : 19.355 이중 검색 [48109 : 207] *** 캐치되지 않은 예외 'NSRangeException'으로 인해 응용 프로그램 종료 중, 이유 : '*** - [NSCFArray objectAtIndex :] : 인덱스 (4) 넘어 (1) ' 2010-07-25 21 : 58 : 19.355 듀얼 검색 [48,109 : 207] 스택 ( 43,292,752, 44,450,604, 43,030,283, 43,030,122, 748,457, 187,239 , 49,603, 3,416,117 , 3,375,658, 330,631 , 42,571,740, 42,567,848, 51,927,197, 51,927,394, 3,056,498, 9476,,536,9330 ) 'NSException'의 인스턴스를 던진 후 호출 terminate –

답변

0

행, 응용 프로그램이 충돌되어

감사 선택려고 할 때입니다 배열의. 예를 들어 배열에 하나의 항목 만 있고 인덱스 3에있는 객체를 요청하면 NSRangeException이 발생합니다. 즉각적인 해결책은 내용을 쿼리하기 전에 배열의 크기를 확인하는 것입니다.

NSArray* exampleArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; 
int items = [exampleArray count]; 
if(indexPath.row < items) { 
    // do stuff 
} 
+0

감사하지만 여러 배열이 있습니다. 각 섹션의 배열입니다. –

+0

예,하지만 didSelectRow에서 세 가지 모두에 액세스하려고합니다. – Justin

+0

나는 그것을 시험해 아직도 부서진다. 배열을 세 번째 배열의 마지막 인덱스로 이동시키면서 아무리 작은 검사와 모든 개체를 수행했습니다. –

관련 문제