2014-12-31 4 views
-1

줄에 "스레드 1 신호 sigabrt"오류가 발생합니다 (주 UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate 클래스]))). 로그에 다음과 m : 세바스찬 켈러에 의해 제안iOS 탭 카운터 응용 프로그램 - 스레드 1 신호 sigabrt 오류

2014-12-31 22:17:16.295 RowCounter[2994:110721] -[__NSCFString objectForKey:]: unrecognized 
selector sent to instance 0x7fa0ea504300 
2014-12-31 22:17:16.298 RowCounter[2994:110721] *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector 
sent to instance 0x7fa0ea504300' 
*** First throw call stack: 
(
0 CoreFoundation      0x0000000102e88f35 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x0000000102b21bb7 objc_exception_throw + 45 
2 CoreFoundation      0x0000000102e9004d -[NSObject(NSObject) 
doesNotRecognizeSelector:] + 205 
3 CoreFoundation      0x0000000102de827c ___forwarding___ + 988 
4 CoreFoundation      0x0000000102de7e18 _CF_forwarding_prep_0 + 120 
5 RowCounter       0x00000001025f1ebc -[RowCounterViewController 
viewDidLoad] + 444 
6 UIKit        0x000000010339aa90 -[UIViewController 
loadViewIfRequired] + 738 
7 UIKit        0x000000010339ac8e -[UIViewController view] + 27 
8 UIKit        0x00000001033be507 -[UINavigationController 
_startCustomTransition:] + 633 
9 UIKit        0x00000001033ca3fe -[UINavigationController 
_startDeferredTransitionIfNeeded:] + 386 
10 UIKit        0x00000001033caf47 -[UINavigationController 
__viewWillLayoutSubviews] + 43 
11 UIKit        0x0000000103510509 -[UILayoutContainerView 
layoutSubviews] + 202 
12 UIKit        0x00000001032ee973 -[UIView(CALayerDelegate) 
layoutSublayersOfLayer:] + 521 
13 QuartzCore       0x0000000106b76de8 -[CALayer layoutSublayers] + 150 
14 QuartzCore       0x0000000106b6ba0e 
_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 
15 QuartzCore       0x0000000106b6b87e 
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
16 QuartzCore       0x0000000106ad963e 
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 
17 QuartzCore       0x0000000106ada74a _ZN2CA11Transaction6commitEv + 390 
18 UIKit        0x000000010327214d _UIApplicationHandleEventQueue + 
2035 
19 CoreFoundation      0x0000000102dbe551 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
20 CoreFoundation      0x0000000102db441d __CFRunLoopDoSources0 + 269 
21 CoreFoundation      0x0000000102db3a54 __CFRunLoopRun + 868 
22 CoreFoundation      0x0000000102db3486 CFRunLoopRunSpecific + 470 
23 GraphicsServices     0x000000010646a9f0 GSEventRunModal + 161 
24 UIKit        0x0000000103275420 UIApplicationMain + 1282 
25 RowCounter       0x00000001025f23c3 main + 115 
26 libdyld.dylib      0x0000000105418145 start + 1 
27 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

- 나는`[RowCounterViewController있는 viewDidLoad]에 문자열 객체에 [object objectForKey:]를 호출하고 있습니다.

는 또한 NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveCount"]; =>이 정말있는 NSDictionary 아니라는 것을 제안했다.

디버깅 목적으로 시도 : NSDictionary *dict = @{}; 및 실행했습니다.

이것은 해당 섹션의 코드입니다. 제가 잘못하고있는 것을 지적 해주십시오.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveCount"] ; 
    NSString *key = [NSString stringWithFormat:@"%ld", (unsigned long)_itemIndex] ; 

    NSNumber *numCounter = [dict objectForKey:key] ; 
    if (numCounter) { 
     counter = [numCounter intValue] ; 
     count.text = [NSString stringWithFormat:@"%d", counter] ; 
    } else { 
     counter = 0 ; 
     count.text = @"0" ; 
    } 
} 

NSUserDefaults와 코드의 다른 비트 :

- (void)saveCount { 
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveCount"] ; 
    NSMutableDictionary *mDict = nil ; 
    if (dict == nil) 
     mDict = [NSMutableDictionary dictionary] ; 
    else 
     mDict = [dict mutableCopy] ; 

    NSString *key = [NSString stringWithFormat:@"%ld", (unsigned long)_itemIndex] ; 
    [mDict setObject:@(counter) forKey:key] ; 

    [[NSUserDefaults standardUserDefaults] setObject:mDict forKey:@"saveCount"] ; 
    [[NSUserDefaults standardUserDefaults] synchronize] ; 
} 

콘솔 10NSLog(@"%@", dict);에 대한 읽기는 당신에게

답변

0

편집 감사합니다 다시 설정하라는 아이폰 시뮬레이터 콘텐츠 및 설정이 도움이 될 것입니다.

이 하나 개의 중요한 라인은 :

2014-12-31 22:17:16.295 RowCounter[2994:110721] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7fa0ea504300 

그것은 당신이 [객체 objectForKey를 :] 호출하는 것을 의미하는 문자열 객체 (objectForKey :

이 일어나고 [RowCounterViewController를 구현하지 않는 viewDidLoad에]

마지막 라인에서
5 RowCounter       0x00000001025f1ebc -[RowCounterViewController viewDidLoad] + 444 
+0

답장을 보내 주셔서 감사합니다. – dicobraz

+0

수정을 참조하십시오. 귀하의 dict이 NSDictionary라고 생각하지 않습니다. –

+0

NSDictionary * dict = [[NSUserDefaults 표준 사용자 정의]] objectForKey : @ "saveCount"]; =>이게 실제로 NSDictionary입니까? –

0

사용

NSInteger numCounter = [[dict objectForKey:key] intValue] ; 
if (numCounter > 0) { 
    count.text = [NSString stringWithFormat:@"%d", numCounter] ; 
} else { 
    numCounter = 0 ; 
    count.text = @"0" ; 
} 
+0

오류 줄 - "포인터 호환에 호환되지 않는 정수" – dicobraz

+0

NSInteger는 기본 유형입니다. 포인터가 필요 없습니다. 불필요한 포인터를 제거하면 if 절은 numCounter가 1과 같은지 확인합니다. –

+0

죄송합니다, 편집 된 코드가 있습니다. @Sebastian 감사합니다. –

관련 문제