2

在此处输入图像描述

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayM objectForKey:]:无法识别的选择器发送到实例 0x12e654c0。

我正在从具有两个字典对象的 Array 中加载 tableview 上的数据。当调用 ViewDidLoad 时,字典对象包含 2 个 nsstring 对象,代码如下

while (sqlite3_step(statement) == SQLITE_ROW) {
    NSString* delID = [NSString stringWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
    NSString* name =[NSString stringWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]; 


    NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    [dict setObject:delID forKey:@"delID"];
    [dict setObject:name forKey:@"name"];
    [self.arr addObject:dict];

它永远不会在第一行崩溃,但在第二行 indexPath.row==1 它总是崩溃,请参阅下面的屏幕截图。感谢帮助

这是我再次填写 self.arr -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController { if ([datePicker1.CurrentDate length]) {

UIButton *btn=(UIButton*)[self.view viewWithTag:btnTag];
[btn setTitle:datePicker1.CurrentDate forState:UIControlStateNormal];
}

if ([self.searchDel.arrSelectDelAdd count ]) 
{
    [self.arr addObject:self.searchDel.arrSelectDelAdd];



    [self.tblDelivery reloadData];

}

}
4

2 回答 2

1

从代码中删除 if 条件。因为它只是将第一个字典添加到数组中,而不是第二个字典。

//if (i==0){
        [self.arr addObject:dict];
//}

尝试这个 :)

于 2012-07-13T06:46:17.107 回答
0

很抱歉打扰大家实际上问题是我正在添加第二个或另一个对象

[self.arr addObject:self.searchDel.arrSelectDelAdd]; //Incorrect, that is adding NSArray type not dictionary

然后在 cellForRowAtIndexPath 中获取值

NSDictionary *dict=[arr objectAtIndex:indexPath.row];//here dict will contain NSSArray type not dict type object its causing to crash app.

cell.lblID.text=(NSString*)[dict objectForKey:@"delID"];// at this line.
cell.lblName.text=(NSString*)[dict objectForKey:@"name"];


[self.arr addObjectsFromArray:self.searchDel.arrSelectDelAdd]; // correct, thats the solution giving contents of NSSArray and now working my code 
于 2012-07-13T07:36:02.543 回答