在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;
}
)
);
}
'indexPath + 1'條件的目的是什麼?是'invoiceList'你的數據數組?發佈您的'numberOfRows'方法代碼。 –
你確定這個異常肯定發生在你告訴我們的objectAtIndex行嗎?事先打印invoiceList的類:NSLog(@「%@」,[invoiceList class]) – jarmod
可以提供發票清單NSLog – Jamil