2015-01-14 3 views
1

응용 프로그램 충돌을 일으키는 원인을 파악할 수 없습니다. UITableView는 numberOfRowsInSection 메소드를 사용하여 데이터로 채워진다. 첫 번째 두 레코드를 올바르게로드하지만 세 번째 행이로드 될 때 응용 프로그램이 충돌합니다. 도와주세요.UITableView 예외 iOS

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    myDictionary = self.myArray; 
    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [myDictionary count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"TransHistoryCell"; 

    TransHistoryCell *cell = (TransHistoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];  
    @try 
    { 

     if (cell == nil) 
     { 
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TransHistoryCell" owner:self options:nil]; 
      cell = [nib objectAtIndex:0]; 
     } 

     NSDictionary *currentDictionary = [myDictionary objectAtIndex:indexPath.row]; 

     for(NSDictionary *object in currentDictionary) 
     { 
      NSString *key = [object valueForKey:@"Key"]; 
      NSString *value = [object valueForKey:@"Value"]; 
      if([key isEqualToString:DATE]) 
      { 
       cell.dateLabel.text = value; 
      } 
      else if([key isEqualToString:TRANSACTION_ID]) 
      { 
       cell.transactionIdLabel.text = value; 
      } 
      else if([key isEqualToString:THIRD_PARTY]) 
      { 
       cell.thirdPartyLabel.text = value; 
      } 
      else if([key isEqualToString:AMOUNT]) 
      { 
       cell.amountLabel.text = value; 
      } 
      else if([key isEqualToString:TRANSACTION_DESC]) 
      { 
       cell.transactionDescLabel.text = value; 
      } 
     } 
    } 
    @catch (NSException *exception) 
    { 
     NSLog(@"Exception: %@", exception); 
    } 
    @finally 
    { 
     return cell; 
    } 
} 

예외 :

2015-01-14 09:49:12.808 MobileProject[19580:5974561] -[NSNull length]: unrecognized selector sent to instance 0x103796ce0 
2015-01-14 09:49:12.812 MobileProject 
[19580:5974561] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x103796ce0' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001034edf35 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x0000000102187bb7 objc_exception_throw + 45 
    2 CoreFoundation      0x00000001034f504d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x000000010344d27c ___forwarding___ + 988 
    4 CoreFoundation      0x000000010344ce18 _CF_forwarding_prep_0 + 120 
    5 UIKit        0x00000001009b2f45 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 65 
    6 UIKit        0x00000001009b2da0 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 76 
    7 UIKit        0x00000001009b6852 -[UILabel _intrinsicSizeWithinSize:] + 170 
    8 UIKit        0x00000001009b6932 -[UILabel intrinsicContentSize] + 76 
    9 UIKit        0x0000000100e6cea4 -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 33 
    10 UIKit        0x0000000100e6cc64 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 422 
    11 UIKit        0x0000000100e740d6 -[UIView(AdditionalLayoutSupport) updateConstraints] + 163 
    12 UIKit        0x00000001009b679d -[UILabel updateConstraints] + 272 
    13 UIKit        0x0000000100e736fa -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 248 
    14 UIKit        0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124 
    15 CoreFoundation      0x00000001033f6194 CFArrayApplyFunction + 68 
    16 UIKit        0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153 
    17 Foundation       0x0000000101aead6e -[NSISEngine withBehaviors:performModifications:] + 155 
    18 UIKit        0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124 
    19 CoreFoundation      0x00000001033f6194 CFArrayApplyFunction + 68 
    20 UIKit        0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153 
    21 UIKit        0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124 
    22 UIKit        0x0000000100e73dbe __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96 
    23 UIKit        0x0000000100e73a86 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231 
    24 UIKit        0x0000000100c698b8 -[UITableViewCellContentView updateConstraintsIfNeeded] + 95 
    25 UIKit        0x0000000100e7419e -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 159 
    26 UIKit        0x000000010085ab2d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114 
    27 UIKit        0x0000000100866973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521 
    28 QuartzCore       0x0000000103d6ade8 -[CALayer layoutSublayers] + 150 
    29 QuartzCore       0x0000000103d5fa0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 
    30 QuartzCore       0x0000000103d5f87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
    31 QuartzCore       0x0000000103ccd63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 
    32 QuartzCore       0x0000000103cce74a _ZN2CA11Transaction6commitEv + 390 
    33 QuartzCore       0x0000000103ccedb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89 
    34 CoreFoundation      0x0000000103422dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
    35 CoreFoundation      0x0000000103422d20 __CFRunLoopDoObservers + 368 
    36 CoreFoundation      0x0000000103418b53 __CFRunLoopRun + 1123 
    37 CoreFoundation      0x0000000103418486 CFRunLoopRunSpecific + 470 
    38 GraphicsServices     0x000000010338b9f0 GSEventRunModal + 161 
    39 UIKit        0x00000001007ed420 UIApplicationMain + 1282 
    40 MobileProject     0x0000000100535c83 main + 115 
    41 libdyld.dylib      0x0000000107323145 start + 1 
    42 ???         0x0000000000000002 0x0 + 2 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

답변

1

당신은 당신이 NSString하지만 실제로 NSNull 무슨 생각의 길이를 얻기 위해 노력하고 있습니다. 따라서 키의 '

+0

모두에서 NSNULL 값을 확인하십시오. 네가 맞습니다. 나는 이미 알아 냈어. NSNull 때문에 응용 프로그램이 손상되었습니다. 고마워. 그런데 NSNull을 objective-c에서 처리하는 올바른 방법은 무엇입니까? 나는 이것에 초보자이므로 조언을 부탁드립니다. –

+0

이 링크를 사용하여 http://stackoverflow.com/questions/19546920/how-to-check-nsstring-is-null-or-not을 확인하고 NULL을 받으면 코드에 간단한 코드를 추가하지 않습니다. –