2010-11-30 6 views
0

"잡히지 않는 예외 'NSRangeException으로 인해 종료 애플 리케이션, 이유 :'*** - [NSArray objectAtIndex :] : 경계 24 넘어 인덱스 24 [0123] 정말 길지 않고 여기에 내 .m을 어떻게 두는 지 모르겠습니다. 이 문제를 해결하는 방법을 알려주십시오. 미리 감사드립니다.경계 너머로 아이폰 sdk

코드 :

#import "RootViewController.h" 
#import "FSDAppDelegate.h" 
#import "DetailViewController.h" 
@implementation RootViewController 

#pragma mark - 
#pragma mark Synthesizers 

@synthesize mainTableView; 
@synthesize contentsList; 
@synthesize descArray; 
@synthesize bannerImages; 
@synthesize childController; 
@synthesize searchResults; 
@synthesize savedSearchTerm; 


#pragma mark - 
#pragma mark View methods 

- (void)viewDidLoad 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 


    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Descriptions" ofType:@"plist"]; 

    NSArray *desc = [[NSArray alloc] initWithContentsOfFile:filePath]; 
    self.descArray = desc; 
    [desc release]; 

    UIImage *texas = [UIImage imageNamed:@"1andtexas.jpg"]; 
    UIImage *cali = [UIImage imageNamed:@"2andcalifornia.jpg"]; 
    UIImage *ny = [UIImage imageNamed:@"3andnewyork.jpg"]; 
    UIImage *tmark = [UIImage imageNamed:@"1Tmark.jpg"]; 
    UIImage *walkie = [UIImage imageNamed:@"Walkietalkie.jpg"]; 
    UIImage *onekh = [UIImage imageNamed:@"Tracingpaper.jpg"]; 
    UIImage *onetwonine = [UIImage imageNamed:@"diffusion.jpg"]; 
    UIImage *greycard = [UIImage imageNamed:@"Greycard.jpg"]; 
    UIImage *oneeighty = [UIImage imageNamed:@"Oneeighty.jpg"]; 
    UIImage *two = [UIImage imageNamed:@"Two.jpg"]; 
    UIImage *twofourteen = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofifteen = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twosixteen = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twotwenty = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twotwentynine = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofifty = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftyone = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftytwo = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftythree = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftyfour = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftyfive = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftysix = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftyseven = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *twofiftyeight = [UIImage imageNamed:@"Diffusion.jpg"]; 
    UIImage *thirtytwohk = [UIImage imageNamed:@"3200k.jpg"]; 



    NSArray *banners = [[NSArray alloc] initWithObjects: 
         texas, 
         cali, 
         ny, 
         tmark, 
         walkie, 
         onekh, 
         onetwonine, 
         greycard, 
         oneeighty, 
         two, 
         twofourteen, 
         twofifteen, 
         twosixteen, 
         twotwenty, 
         twotwentynine, 
         twofifty, 
         twofiftyone, 
         twofiftytwo, 
         twofiftythree, 
         twofiftyfour, 
         twofiftyfive, 
         twofiftysix, 
         twofiftyseven, 
         twofiftyeight, 
         thirtytwohk, 
         nil]; 

    self.bannerImages = banners; 

    [banners release]; 


    [super viewDidLoad]; 



    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects: 
          @"#1 or NUMBER ONE", 
          @"#2 or NUMBER TWO", 
          @"#3 or NUMBER THREE", 
          @"1 or ONE", 
          @"10-100,10-1,10-200,10-2,10-4 and 20", 
          @"1000H PAPER", 
          @"129 or HEAVY FROST", 
          @"18% GRAY or GREY CARD", 
          @"180 DEGREE RULE", 
          @"2 or TWO", 
          @"214 or FULL TOUGH SPUN", 
          @"215 or HALF TOUGH SPUN", 
          @"216 or FULL WHITE DIFFUSION", 
          @"220 or WHITE FROST", 
          @"229 or QUARTER TOUGH SPUN", 
          @"250 or HALF WHITE DIFFUSION", 
          @"251 or QUARTER WHITE DIFFUSION", 
          @"252 or EIGHTH WHITE DIFFUSION", 
          @"253 or FULL HAMPSHIRE", 
          @"254 or NEW HAMPSHIRE", 
          @"255 or HOLLYWOOD FROST", 
          @"256 or HALF HAMPSHIRE FROST", 
          @"257 or QUARTER HAMPSHIRE FROST", 
          @"258 or EIGHTH HAMPSHIRE FROST", 
          @"3200K or TUNGSTEN", 
          nil]; 
    [self setContentsList:array]; 
    [array release], array = nil; 

    if ([self savedSearchTerm]) 
    { 
     [[[self searchDisplayController] searchBar] setText:[self savedSearchTerm]]; 
    } 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    [super viewWillAppear:animated]; 

    [[self mainTableView] reloadData]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

#pragma mark - 
#pragma mark Table view datasource methods 

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 

    NSMutableArray *toBeReturned = [[NSMutableArray alloc]init]; 
    for(char c = 'A'; c <= 'Z'; c++) [toBeReturned addObject:[NSString stringWithFormat:@"%c",c]]; 
    return toBeReturned; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    NSInteger rows; 

    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     rows = [[self searchResults] count]; 
    else 
     rows = [[self contentsList] count]; 

    return [contentsList count]; 
    return rows; 

    NSLog(@"rows is: %d", rows); 
    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

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

    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    NSInteger row = [indexPath row]; 
    NSString *contentForThisRow = nil; 

    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     contentForThisRow = [[self searchResults] objectAtIndex:row]; 
    else 
     contentForThisRow = [[self contentsList] objectAtIndex:row]; 

    static NSString *CellIdentifier = @"CellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    [[cell textLabel] setText:contentForThisRow]; 

    cell.textLabel.text = [contentsList objectAtIndex:indexPath.row]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 

    return cell; 
} 

#pragma mark - 
#pragma mark Table view delegate methods 

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 50; 
} 

-(NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section 
{ 
    return @"Film Set Decipher"; 
} 

-(void) tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    FSDAppDelegate *delegate = (FSDAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    detailVC.banner = [bannerImages objectAtIndex:indexPath.row]; 
    detailVC.description = [descArray objectAtIndex:indexPath.row]; 
    detailVC.title = [contentsList objectAtIndex:indexPath.row]; 
    self.childController = detailVC; 
    [delegate.navigationController pushViewController:childController animated:YES]; 

    [detailVC release]; 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

#pragma mark - 
#pragma mark UISearchDisplayController Delegate Methods 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller 
shouldReloadTableForSearchString:(NSString *)searchString 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    [self handleSearchForTerm:searchString]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
    return YES; 
} 

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    [self setSavedSearchTerm:nil]; 

    [[self mainTableView] reloadData]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 
#pragma mark - 
#pragma mark Memory Management 

- (void)didReceiveMemoryWarning { 
    NSLog(@"Memory warning!"); 
    [super didReceiveMemoryWarning]; 
} 
- (void)dealloc 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    [mainTableView release]; mainTableView = nil; 
    [contentsList release]; contentsList = nil; 
    [descArray release]; descArray = nil; 
    [bannerImages release]; bannerImages = nil; 
    [childController release]; childController = nil; 
    [searchResults release], searchResults = nil; 
    [savedSearchTerm release], savedSearchTerm = nil; 

    [super dealloc]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

- (void)viewDidUnload { 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    self.mainTableView = nil; 
    self.contentsList = nil; 
    self.descArray = nil; 
    self.bannerImages = nil; 
    self.childController = nil; 

    [super viewDidUnload]; 

    [self setSavedSearchTerm:[[[self searchDisplayController] searchBar] text]]; 

    [self setSearchResults:nil]; 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 

} 

- (void)handleSearchForTerm:(NSString *)searchTerm 
{ 
    NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 

    [self setSavedSearchTerm:searchTerm]; 

    if ([self searchResults] == nil) 
    { 
     NSMutableArray *array = [[NSMutableArray alloc] init]; 
     [self setSearchResults:array]; 
     [array release], array = nil; 
    } 

    [[self searchResults] removeAllObjects]; 

    if ([[self savedSearchTerm] length] != 0) 
    { 
     for (NSString *currentString in [self contentsList]) 
     { 
      if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) 
      { 
       [[self searchResults] addObject:currentString]; 
      } 
     } 
    } 

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 
} 

@end 

은 충돌하게 무슨 문제가 이미지를 모두하지 않았다 대상> 복사 번들 리소스 폴더에 복사이었다 밝혀, 그리고 이잖아!?!? 대단히 감사합니다!

+0

코드를 올바르게 포맷 할 수 있습니까? 그러면 문제를 쉽게 파악할 수 있습니다. –

답변

0

오류는 배열에 24 개의 요소가 있지만 25 번째 요소에 액세스하려고하고 있다고 말합니다. 따라서 25 번째 요소에 액세스하려고 시도하는 코드를 게시해야합니다. 또는 24 요소 배열에서 25 번째 요소를 찾으려는 이유를 파악하십시오.

편집 : didSelectRowAtIndexPath :

po descArray 

또는 단지 :

gdb를> 프롬프트에서 다음

당신은있는 tableView 첫 번째 줄에 또는 그래서 중단 점을 설정해야합니다

p(int) [descArray count] 

또는 얼마나 많은 항목이 실제로 있는지 보려면 변수 창을 확인하십시오. 그 시점에서 descArray. 다른 두 배열에 대해 필요한 경우 반복합니다. 다시

편집 :

당신은 우리의있는 tableView에서 (아마도 무관) 또 다른 문제가 있습니다 numberOfRowsInSection :

을 당신은 contentList 모든 시간을 계산 돌아갑니다. NSLog를 포함하여 반환 된 행에는 절대 도달하지 않습니다. C에서 첫 번째 리턴을 마자 마자, 당신은 즉시 그 방법으로부터 돌아올 것입니다. 나는 그것이 당신의 즉각적인 문제라고 생각하지 않지만, 당신이 검색 작업을 시작할 때 일어날 또 다른 문제입니다. descArray contentsList

이러한 배열 테이블 뷰의 행의 수와 동일한 객체의 수를 갖지 않는 이러한 bannerImages의 개체

+0

나는 그것이 무엇 자체에 디버거를 실행하고,이 팝업 것입니다 : – Draken182

+0

0x9515116c <+0000> MOV $ 0xc0025, % eax에 0x95151171 <+0005> 전화 0x950f03d8 <_sysenter_trap> 0x95151176 <+0010> 재에 0x95151186 <__kill+26> 0x95151178 <+0012> 전화 0x9515117d <__kill+17> 0x9515117d <+0017> % EDX 0x9515117e <+0018> mov 인 0xb4ef767 (%의 EDX), % EDX 0x95151184 <+0024> JMP * % EDX 0x95151186 <+0026> RET – Draken182

+0

어떤 스택 추적이 생겼 팝업? 이 충돌이 어디에서 일어나는지 알려줄 것입니다. 그럼 누군가가 당신을 도울 수 있도록 코드를 게시해야합니다. –

0

수표 번호.

(배열을 준비하고 tableview 데이터 소스를 올바르게 확인하고 메소드를 위임해야합니다.) 또는 솔루션을 얻지 못하면 여기에 모든 코드를 입력하십시오.