2013-12-14 4 views
0

for 루프를 사용하여 숫자 1 - 10의 numbers라는 배열을 채우려고합니다. 그러나, 내가 알지 못하는 어떤 이유로 모든 것이 충돌합니다. 모든 충돌, 내가 무엇을하고 있어요 왜for 루프로 NSMutableArray 채우기

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

나도 몰라 :

for (int counter = 0; counter < 10; counter++) { 

    if (!numbers) 
    { 

     self.numbers = [[NSMutableArray alloc]init]; 

    } 

    [numbers addObject: [NSNumber numberWithInt:counter]]; 

} 

NSLog(@"%lu", [numbers count]); 

그리고 테이블 셀에 숫자를 넣어 : 여기

내가 무엇을 시도했다입니다 나에게 맞는 것 같다.

2013-12-13 20:52:29.788 TopNumbers[4003:70b] 10 
2013-12-13 20:52:29.792 TopNumbers[4003:70b] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000002 
2013-12-13 20:52:29.796 TopNumbers[4003:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000002' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010188e795 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x00000001015f1991 objc_exception_throw + 43 
    2 CoreFoundation      0x000000010191fbad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x000000010188009d ___forwarding___ + 973 
    4 CoreFoundation      0x000000010187fc48 _CF_forwarding_prep_0 + 120 
    5 Foundation       0x00000001011e89cb -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 46 
    6 Foundation       0x00000001011e94a6 -[NSConcreteMutableAttributedString initWithString:attributes:] + 249 
    7 UIKit        0x00000001003c7497 -[UILabel _setText:] + 85 
    8 TopNumbers       0x0000000100001b40 -[XYZViewController tableView:cellForRowAtIndexPath:] + 352 
    9 UIKit        0x000000010031fb8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348 
    10 UIKit        0x0000000100307836 -[UITableView _updateVisibleCellsNow:] + 2297 
    11 UIKit        0x0000000100318381 -[UITableView layoutSubviews] + 207 
    12 UIKit        0x00000001002afb27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354 
    13 QuartzCore       0x0000000103df5a22 -[CALayer layoutSublayers] + 151 
    14 QuartzCore       0x0000000103dea589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363 
    15 UIKit        0x00000001002a4470 -[UIView(Hierarchy) layoutBelowIfNeeded] + 521 
    16 UIKit        0x0000000100360a96 -[UINavigationController _layoutViewController:] + 1077 
    17 UIKit        0x000000010035e374 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 395 
    18 UIKit        0x000000010029534e -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 235 
    19 UIKit        0x0000000100293e44 +[UIViewAnimationState popAnimationState] + 281 
    20 UIKit        0x000000010051355e -[UINavigationTransitionView transition:fromView:toView:] + 2504 
    21 UIKit        0x0000000100512b94 -[UINavigationTransitionView transition:toView:] + 25 
    22 UIKit        0x0000000100361797 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2893 
    23 UIKit        0x0000000100361a47 -[UINavigationController _startDeferredTransitionIfNeeded:] + 547 
    24 UIKit        0x00000001003624f8 -[UINavigationController __viewWillLayoutSubviews] + 43 
    25 UIKit        0x00000001004767e1 -[UILayoutContainerView layoutSubviews] + 202 
    26 UIKit        0x00000001002afb27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354 
    27 QuartzCore       0x0000000103df5a22 -[CALayer layoutSublayers] + 151 
    28 QuartzCore       0x0000000103dea589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363 
    29 QuartzCore       0x0000000103df5956 -[CALayer layoutIfNeeded] + 162 
    30 UIKit        0x000000010034ffc2 -[UIViewController window:setupWithInterfaceOrientation:] + 264 
    31 UIKit        0x000000010028eb4d -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4360 
    32 UIKit        0x000000010028da3f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36 
    33 UIKit        0x000000010028d98f -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101 
    34 UIKit        0x000000010028cc9e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377 
    35 UIKit        0x0000000100343d4a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147 
    36 UIKit        0x0000000100287a87 -[UIWindow addRootViewControllerViewIfPossible] + 506 
    37 UIKit        0x0000000100287bd5 -[UIWindow _setHidden:forced:] + 275 
    38 UIKit        0x0000000100290ca2 -[UIWindow makeKeyAndVisible] + 51 
    39 UIKit        0x000000010024f0c8 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1449 
    40 UIKit        0x0000000100252be8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660 
    41 UIKit        0x0000000100263aab -[UIApplication handleEvent:withNewEvent:] + 3092 
    42 UIKit        0x0000000100263f1e -[UIApplication sendEvent:] + 79 
    43 UIKit        0x00000001002542be _UIApplicationHandleEvent + 618 
    44 GraphicsServices     0x0000000103996bb6 _PurpleEventCallback + 762 
    45 GraphicsServices     0x000000010399667d PurpleEventCallback + 35 
    46 CoreFoundation      0x0000000101810819 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41 
    47 CoreFoundation      0x00000001018105ee __CFRunLoopDoSource1 + 478 
    48 CoreFoundation      0x0000000101839ab3 __CFRunLoopRun + 1939 
    49 CoreFoundation      0x0000000101838f33 CFRunLoopRunSpecific + 467 
    50 UIKit        0x00000001002524bd -[UIApplication _run] + 609 
    51 UIKit        0x0000000100254043 UIApplicationMain + 1010 
    52 TopNumbers       0x0000000100001fd3 main + 115 
    53 libdyld.dylib      0x0000000101f1d5fd start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 
+0

또한 NSLog (@ "% i", [numbers count])가있는 이유를 알 수 없으므로 Xcode에서 경고를 '% lu'로 변경합니다. – Nathaly

+0

어디에서 충돌 했습니까? 'numbers'와'self.numbers'는 같은 객체를 참조합니까? – KudoCC

+0

@KudoCC, 나는 오류를 추가했다. 그리고 그렇습니다. – Nathaly

답변

0

당신은 사용해야

cell.textLabel.text = [[numbers objectAtIndex:indexPath.row] stringValue]; 
+0

누군가가 downvotes 할 때, 왜 그런지를 설명하는 글을 올리십시오. –

1

UILabel의의 텍스트 속성은 문자열을 원하지만, 당신은 그것에게의 NSNumber를 제공하고 있습니다 :

이 오류를 받고 있어요. 숫자의 문자열 값을 가져 가고 싶습니다.

1

사용이 : cell.textLabel.text = [NSString stringWithFormat:@"%@", [numbers objectAtIndex:indexPath.row]] ;

내가 주석 경우 또한 "말을 [숫자 addObject이 : [의 NSNumber numberWithInt가 : 카운터]] ;,가 충돌하지 않습니다 ... " 왜냐하면 주석 처리하면 숫자가 0이므로 셀이 필요하지 않기 때문입니다.