2011-12-20 3 views
0

내 개발 아이폰 OS 응용 프로그램은 때때로 응용 프로그램 위임에 호출되는 방법 addSubview: 후 종료입니다 (하지만 난 모르겠어요 removeFromSuperview:도 포함) : 그 보였다 무엇아이폰 OS는 : 때때로 응용 프로그램은 종료

[self.tabBarController.view removeFromSuperview];  
[self.window addSubview:navigationController.view]; 

로그에 :

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x019b75a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x01c41313 objc_exception_throw + 44 
    2 CoreFoundation      0x019ad0a5 -[__NSArrayM objectAtIndex:] + 261 
    3 <app_name>       0x000186dd -[TableViewController tableView:numberOfRowsInSection:] + 205 
    4 UIKit        0x00a742b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834 
    5 UIKit        0x00a71eb1 -[UITableViewRowData numberOfRowsInSection:] + 110 
    6 UIKit        0x00b60807 -[UISearchDisplayController _updateNoSearchResultsMessageVisiblity] + 115 
    7 Foundation       0x01029669 _nsnote_callback + 145 
    8 CoreFoundation      0x0198f9f9 __CFXNotificationPost_old + 745 
    9 CoreFoundation      0x0190e93a _CFXNotificationPostNotification + 186 
    10 Foundation       0x0101f20e -[NSNotificationCenter postNotificationName:object:userInfo:] + 134 
    11 UIKit        0x008df649 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 4581 
    12 UIKit        0x008d9254 -[UIWindow _setRotatableViewOrientation:duration:force:] + 89 
    13 UIKit        0x008db38f -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 794 
    14 UIKit        0x008d9081 -[UIWindow setDelegate:] + 252 
    15 UIKit        0x00964dee -[UIViewController _tryBecomeRootViewControllerInWindow:] + 106 
    16 UIKit        0x00975340 -[UINavigationController viewDidMoveToWindow:shouldAppearOrDisappear:] + 72 
    17 UIKit        0x008f0e4b -[UIView(Internal) _didMoveFromWindow:toWindow:] + 918 
    18 UIKit        0x008efa60 -[UIView(Hierarchy) _postMovedFromSuperview:] + 166 
    19 UIKit        0x008e8750 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1080 
    20 UIKit        0x008e6aa3 -[UIView(Hierarchy) addSubview:] + 57 
    21 <app_name>       0x00004971 -[AppDelegate requestFinished:] + 993 
    22 <app_name>       0x0003e65b -[ASIHTTPRequest reportFinished] + 171 
    23 Foundation       0x0103e94e __NSThreadPerformPerform + 251 
    24 CoreFoundation      0x019988ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
    25 CoreFoundation      0x018f688b __CFRunLoopDoSources0 + 571 
    26 CoreFoundation      0x018f5d86 __CFRunLoopRun + 470 
    27 CoreFoundation      0x018f5840 CFRunLoopRunSpecific + 208 
    28 CoreFoundation      0x018f5761 CFRunLoopRunInMode + 97 
    29 GraphicsServices     0x01db11c4 GSEventRunModal + 217 
    30 GraphicsServices     0x01db1289 GSEventRun + 115 
    31 UIKit        0x008c5c93 UIApplicationMain + 1160 
    32 <app_name>       0x00002a30 main + 192 
    33 <app_name>       0x00002255 start + 53 
) 
terminate called throwing an exception 

이 로그로 앱이 종료 된 이유를 어떻게 알 수 있습니까? 고맙습니다.

참고 : 편집 1과 편집 2가 제거되었습니다.

편집 3 :이 tableView:numberOfRowsInSection: 방법의 코드를 구현 나를 위해 작동합니다 : 당신의 스택 추적에서

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView == self.searchDisplayController.searchResultsTableView) 
    { 
     if (filteredSectionListOfAddressBook && filteredSectionListOfAddressBook.count) 
     { 
      return [[filteredSectionListOfAddressBook objectAtIndex:section] count]; 
     } 
     else 
     { 
      return 0; 
     } 
    } 
    else if (tableView == self.tableView) 
    { 
     if (sectionListOfAddressBook && sectionListOfAddressBook.count) 
     { 
      return [[sectionListOfAddressBook objectAtIndex:section] count]; 
     } 
     else 
     { 
      return 0; 
     } 
    } 

    return 0; 
} 

답변

3

-있는 tableview이 - 테이블을 채우는 데이터가 있는지 확인해야합니다. 확인하여 데이터 오류가

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array 
당신은 순간을 보장 할 수

에서 오는 그게 전부가 없다는 것을

있는 tableView : numberOfRowsInSection : 0을 반환;

TableViews 대리자 메서드를 구현 했습니까?

읽기 여기 About Table Views in iOS-Based Applications

여기

UITableViewDataSource Protocol Reference

UITableViewDelegate Protocol Reference

+0

로 전송. 나는'tableView : numberOfRowsInSection :'이 빈 배열의 수를 반환하지 않도록 노력했다. 내 코드에는 테이블 뷰 대리자도 포함되어 있지만 어떤 방법을 고려해야할지 모르겠다. 고마워. – Protocole

+0

네 말이 맞아. 이 에러는'tableView : numberOfRowsInSection :'의 빈 배열에서'objectAtIndex :'메소드가 호출 되었기 때문에 발생합니다. 이전 구현의'tableView : numberOfRowsInSection :'은 빈 배열을 검사하는 것을 포함하지 않았습니다. 다시 한번 감사드립니다. – Protocole

+0

당신을 환영합니다! – Damo

0

여기에 대해 난 그냥 내 코드에서이 같은 문제로 달리고, 나는 그것이 검색 위임에 의한 것을 발견 검색 창과 테이블 참조를 붙잡습니다. 이 속성을 searchDisplayControllerDidEndSearch에서 nil로 설정하면 문제가 해결됩니다. 이것은 순환 참조 루프에 의해 발생했을 가능성이 큽니다. 스택 추적과 같이 보았다 :

는 [__NSArrayM _updateNoSearchResultsMessageVisiblity]

: 인식 할 수없는 선택기 내 편집 질문에서 봐 주시기 바랍니다 예를 0x21c350

#0 0x3369a1c8 in objc_exception_throw() 
#1 0x338b5aca in -[NSObject doesNotRecognizeSelector:]() 
#2 0x338b4944 in __forwarding__() 
#3 0x3380f680 in _forwarding_prep_0__() 
#4 0x30e5aff8 in -[UISearchResultsTableView _numberOfRowsDidChange]() 
#5 0x30d6c3b2 in -[UITableView noteNumberOfRowsChanged]() 
#6 0x30d6bf4e in -[UITableView reloadData]() 
관련 문제