key/value returns nil on phone only
- Get link
- X
- Other Apps
my code works fine on simulator. however, i'm getting error message when running on iphone 4s:
2012-04-25 12:30:24.702 design3rcgp[1812:707] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfdictionary setobject:forkey:]: attempt insert nil value (key: cellimage)'
code:
this works fine on simulator. why?code:- (void)viewdidload { nsmutabledictionary *dictionary1 = [nsmutabledictionary dictionarywithcapacity:3]; nsmutabledictionary *dictionary2 = [nsmutabledictionary dictionarywithcapacity:3]; nsmutabledictionary *dictionary3 = [nsmutabledictionary dictionarywithcapacity:3]; [dictionary1 setobject:[[nsstring alloc] initwithstring:@"podcasts"] forkey:@"cellname"]; [dictionary1 setobject:[uiimage imagenamed:@"podcasticon"] forkey:@"cellimage"]; [dictionary2 setobject:[[nsstring alloc] initwithstring:@"briefings"] forkey:@"cellname"]; [dictionary2 setobject:[uiimage imagenamed:@"essentialicon"] forkey:@"cellimage"]; [dictionary3 setobject:[[nsstring alloc] initwithstring:@"essential updates"] forkey:@"cellname"]; [dictionary3 setobject:[uiimage imagenamed:@"eknupdicon"] forkey:@"cellimage"]; array = [[nsarray alloc] initwithobjects: dictionary1, dictionary2, dictionary3, nil]; } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [array count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static temp1cell *cell; static nsstring *cellidentifier = @"cell"; if (!cell) { cell = [[temp1cell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } cell = (temp1cell*)[tableview dequeuereusablecellwithidentifier:cellidentifier]; nsdictionary *dictionary = [array objectatindex:indexpath.row]; cell.mainlabel.text = [dictionary objectforkey:@"cellname"]; cell.imageview.image = [dictionary objectforkey:@"cellimage"]; return cell; }
your code failing on 1 of these lines:
because you're not loading image successfully, hence trying insert nil dictionarycode:[dictionary1 setobject:[uiimage imagenamed:@"podcasticon"] forkey:@"cellimage"]; [dictionary2 setobject:[uiimage imagenamed:@"essentialicon"] forkey:@"cellimage"]; [dictionary3 setobject:[uiimage imagenamed:@"eknupdicon"] forkey:@"cellimage"];
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
- Get link
- X
- Other Apps
Comments
Post a Comment