繁体   English   中英

iOS App崩溃-无法识别的选择器发送到实例

[英]IOS App crashes - unrecognized selector sent to instance

在tableView:cellForRowAtIndexpath方法中,我的代码如下。

当我注释掉双星号(*)中包含的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;

}

引发的异常是:

-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0'

*** First throw call stack:

(
0   CoreFoundation                      0x000000010fbd1f35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010f63ebb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010fbd904d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010fb3127c ___forwarding___ + 988
4   CoreFoundation                      0x000000010fb30e18 _CF_forwarding_prep_0 + 120
5   MobileWalletBanking                 0x000000010cf0037f -[MyViewController tableView:cellForRowAtIndexPath:] + 479
6   UIKit                               0x000000010dd9b4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
7   UIKit                               0x000000010dd7afb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
8   UIKit                               0x000000010dd90e3c -[UITableView layoutSubviews] + 213
9   UIKit                               0x000000010dd1d973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
10  QuartzCore                          0x000000010d2bade8 -[CALayer layoutSublayers] + 150
...    
)

编辑:发票清单的NSLog:

{
    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;
            }
        )
    );
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM