由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSArrayM objectForKey:]:无法识别的选择器发送到实例0x12e654c0。
我从具有两个字典对象的Array上加载tableview上的数据。当ViewDidLoad调用代码时,Dictionary对象包含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];
}
}
答案 0 :(得分:1)
从代码中删除if条件。因为它只是将第一个字典添加到数组而不是第二个。
//if (i==0){
[self.arr addObject:dict];
//}
试试这个:)
答案 1 :(得分: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