2015-11-12 45 views
0

在tableView:cellForRowAtIndexpath方法中,我的代码如下。IOS应用程序崩溃 - 无法识别的选择器发送到实例

当我注释到包含在双星号(*)中的if条件时,该应用程序崩溃,并出现下面提到的异常。如果我取消注释,那么它工作正常。请帮助,因为我是Objective-C的新手。

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

    cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

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

    **if (invoiceList.count == indexPath.row + 1)** 
    { 
     NSMutableDictionary *currentDictionary = [invoiceList objectAtIndex:indexPath.row];   
     cell.invoiceDetails = currentDictionary; 

     for (NSString *key in [cell.invoiceDetails allKeys]) { 
      NSString *value = [cell.invoiceDetails valueForKey:key]; 

      if([key isEqualToString:MERCHANT_NAME]){ 
       cell.merchantNameValue.text = (value == (id)[NSNull null]) ? @"" : value; 
      } 

      if([key isEqualToString:INVOICE_ID]){ 
       cell.invoiceIdValue.text = (value == (id)[NSNull null]) ? @"" : value; 
      } 

      if([key isEqualToString:TOTAL_AMOUNT]){ 
       cell.totalAmountValue.text = (value == (id)[NSNull null]) ? @"" : value; 
      } 
     } 
    } 

    return cell; 

} 

抛出异常是:

编辑: 的NSLog invoiceList的:

{ 
    501 = 72; 
    610 = Merchant1; 
    611 = Merchant1; 
    612 = 51573; 
    615 = 51573; 
    616 = "07/08/2015 00:00:00"; 
    617 = "64.01"; 
    618 = 498; 
    619 = 498; 
    662 =  (
       { 
      501 = 72; 
      520 = "15.18"; 
      615 = 51573; 
      616 = "07/08/2015 00:00:00"; 
      620 = 43; 
      621 = "15.18"; 
      623 = True; 
      624 = 43; 
      740 = “Text1"; 
     }, 
       { 
      501 = 72; 
      520 = 0; 
      615 = 51573; 
      616 = "07/08/2015 00:00:00"; 
      620 = 10; 
      621 = 0; 
      623 = True; 
      624 = 10; 
      740 = “Text2"; 
     }, 
       { 
      501 = 72; 
      520 = "37.63"; 
      615 = 51573; 
      616 = "07/08/2015 00:00:00"; 
      620 = 2; 
      621 = "37.63"; 
      623 = True; 
      624 = 2; 
      740 = “Text3"; 
     }, 
       { 
      501 = 72; 
      520 = "11.20"; 
      615 = 51573; 
      616 = "07/08/2015 00:00:00"; 
      620 = 3; 
      621 = "11.20"; 
      623 = True; 
      624 = 3; 
      740 = “Text4"; 
     }, 
       { 
      501 = 72; 
      520 = 0; 
      615 = 51573; 
      616 = "07/08/2015 00:00:00"; 
      620 = 14; 
      621 = 0; 
      623 = True; 
      624 = 14; 
      740 = “Text5"; 
     } 
    ); 
    663 =  (
       (
         { 
       Key = 501; 
       Value = 83; 
      }, 
         { 
       Key = Name; 
       Value = "INVOICE_CONNECTION_PROPERTIES"; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 610; 
       Value = ""; 
      }, 
         { 
       Key = 615; 
       Value = 51573; 
      }, 
         { 
       Key = 620; 
       Value = 1; 
      }, 
         { 
       Key = "SERVICE_NAME"; 
       Value = “Text1"; 
      }, 
         { 
       Key = "FIELD_1"; 
       Value = 4272035; 
      }, 
         { 
       Key = "FIELD_1_CONNECTION_FIELD_ID"; 
       Value = 000000000000481; 
      }, 
         { 
       Key = "FIELD_1_QS_NAME"; 
       Value = "Id"; 
      }, 
         { 
       Key = "FIELD_1_QS_VALUE"; 
       Value = "Id"; 
      }, 
         { 
       Key = "FIELD_2"; 
       Value = 10; 
      }, 
         { 
       Key = "FIELD_2_CONNECTION_FIELD_ID"; 
       Value = 000000000000482; 
      }, 
         { 
       Key = "FIELD_2_QS_NAME"; 
       Value = "index1"; 
      }, 
         { 
       Key = "FIELD_2_QS_VALUE"; 
       Value = "index1"; 
      }, 
         { 
       Key = "FIELD_3"; 
       Value = ""; 
      }, 
         { 
       Key = "FIELD_3_IS_MODIFIED"; 
       Value = 1; 
      }, 
         { 
       Key = "FIELD_3_CONNECTION_FIELD_ID"; 
       Value = 000000000000483; 
      }, 
         { 
       Key = "FIELD_3_QS_NAME"; 
       Value = "index2"; 
      }, 
         { 
       Key = "FIELD_3_QS_VALUE"; 
       Value = "index2"; 
      }, 
         { 
       Key = "FIELD_4"; 
       Value = R; 
      }, 
         { 
       Key = "FIELD_4_CONNECTION_FIELD_ID"; 
       Value = 000000000000488; 
      }, 
         { 
       Key = "FIELD_4_QS_NAME"; 
       Value = "index_Type"; 
      }, 
         { 
       Key = "FIELD_4_QS_VALUE"; 
       Value = "Index_Type"; 
      } 
     ), 
       (
         { 
       Key = 501; 
       Value = 83; 
      }, 
         { 
       Key = Name; 
       Value = "INVOICE_CONNECTION_PROPERTIES"; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 610; 
       Value = ""; 
      }, 
         { 
       Key = 615; 
       Value = 51573; 
      }, 
         { 
       Key = 620; 
       Value = 2; 
      }, 
         { 
       Key = "SERVICE_NAME"; 
       Value = “Text2"; 
      }, 
         { 
       Key = "FIELD_1"; 
       Value = 4272033; 
      }, 
         { 
       Key = "FIELD_1_CONNECTION_FIELD_ID"; 
       Value = 000000000000481; 
      }, 
         { 
       Key = "FIELD_1_QS_NAME"; 
       Value = "Id"; 
      }, 
         { 
       Key = "FIELD_1_QS_VALUE"; 
       Value = "Id"; 
      }, 
         { 
       Key = "FIELD_2"; 
       Value = 3; 
      }, 
         { 
       Key = "FIELD_2_CONNECTION_FIELD_ID"; 
       Value = 000000000000482; 
      }, 
         { 
       Key = "FIELD_2_QS_NAME"; 
       Value = "index1"; 
      }, 
         { 
       Key = "FIELD_2_QS_VALUE"; 
       Value = "index1"; 
      }, 
         { 
       Key = "FIELD_3"; 
       Value = ""; 
      }, 
         { 
       Key = "FIELD_3_IS_MODIFIED"; 
       Value = 1; 
      }, 
         { 
       Key = "FIELD_3_CONNECTION_FIELD_ID"; 
       Value = 000000000000483; 
      }, 
         { 
       Key = "FIELD_3_QS_NAME"; 
       Value = "index2"; 
      }, 
         { 
       Key = "FIELD_3_QS_VALUE"; 
       Value = "index2"; 
      }, 
         { 
       Key = "FIELD_4"; 
       Value = C; 
      }, 
         { 
       Key = "FIELD_4_CONNECTION_FIELD_ID"; 
       Value = 000000000000488; 
      }, 
         { 
       Key = "FIELD_4_QS_NAME"; 
       Value = "index_type"; 
      }, 
         { 
       Key = "FIELD_4_QS_VALUE"; 
       Value = "index_type"; 
      } 
     ) 
    ); 
    664 =  (
       (
         { 
       Key = 501; 
       Value = 73; 
      }, 
         { 
       Key = 625; 
       Value = 000000000000481; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 626; 
       Value = "id"; 
      }, 
         { 
       Key = 627; 
       Value = 1; 
      }, 
         { 
       Key = 590; 
       Value = True; 
      } 
     ), 
       (
         { 
       Key = 501; 
       Value = 73; 
      }, 
         { 
       Key = 625; 
       Value = 000000000000482; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 626; 
       Value = "index1"; 
      }, 
         { 
       Key = 627; 
       Value = 2; 
      }, 
         { 
       Key = 590; 
       Value = True; 
      } 
     ), 
       (
         { 
       Key = 501; 
       Value = 73; 
      }, 
         { 
       Key = 625; 
       Value = 000000000000483; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 626; 
       Value = "index2"; 
      }, 
         { 
       Key = 627; 
       Value = 3; 
      }, 
         { 
       Key = 590; 
       Value = True; 
      } 
     ), 
       (
         { 
       Key = 501; 
       Value = 73; 
      }, 
         { 
       Key = 625; 
       Value = 000000000000488; 
      }, 
         { 
       Key = 611; 
       Value = Merchant1; 
      }, 
         { 
       Key = 626; 
       Value = "index_type"; 
      }, 
         { 
       Key = 627; 
       Value = 4; 
      }, 
         { 
       Key = 590; 
       Value = True; 
      } 
     ) 
    ); 
} 
+0

'indexPath + 1'条件的目的是什么?是'invoiceList'你的数据数组?发布您的'numberOfRows'方法代码。 –

+0

你确定这个异常肯定发生在你告诉我们的objectAtIndex行吗?事先打印invoiceList的类:NSLog(@“%@”,[invoiceList class]) – jarmod

+0

可以提供发票清单NSLog – Jamil

回答

0

您正在检查是否(invoiceList.count == indexPath.row + 1)但不是它,请使用if(invoiceList.count> indexPath.row)。还请检查“numberOfRowsInIndexpath”作为invoiceList.count返回。

+0

numberOfRowsInIndexpath正在返回invoiceList.count。但问题是如果if条件未被注释,那么相同的代码正常工作。 –

+0

invoiceList是这个字典或数组吗? –

相关问题