Reputation: 3918
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x12e654c0.
I am loading data on tableview from Array that has two dictionary objects. Dictionary object contains 2 nsstring object when ViewDidLoad called the code is below
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];
It never crash for first row but on second row indexPath.row==1 it always crash please see the screen shot below. Thanks for help
Here is I am filling self.arr again -(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];
}
}
Upvotes: 2
Views: 3058
Reputation: 138
Remove the if condition from your code. As it is just adding first dictionary into the array not the second one.
//if (i==0){
[self.arr addObject:dict];
//}
Try this :)
Upvotes: 1
Reputation: 3918
Sorry to bother all of you Actually the problem is that I am adding second or another object like
[self.arr addObject:self.searchDel.arrSelectDelAdd]; //Incorrect, that is adding NSArray type not dictionary
then getting values in 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
Upvotes: 0