-1

I have a table view in my XCode (IOS) that is passing data to my second table view

FirstTableViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if([segue.identifier isEqualToString:@"ShowSecond"]){
      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
      SecondViewController *List = segue.destinationViewController;
      List.cat = [myObjectCat objectAtIndex:indexPath.row];
   }
}

SecondTableViewController.h: This is what I have

@property (nonatomic,weak) NSDictionary *cat;

SecondTableViewController.m

for (NSDictionary *clickresult in cat) {
    NSString *title_cat = [clickresult objectForKey:@"name"];
    NSLog(@"%@", title_cat);
}

When running the code I get the following error:

WebService[7153:90b] 0 WebService[7153:90b] -[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x9ae0 WebService[7153:90b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x9ae0'

This is what I see on the left side of the debugger when running the code

cat = (_NSDictionaryl *) class name = _NSDictionaryl 
 -> [0] = @"name" : @"This is my first title"
 -> [1] = @"icon" : @"icon.png"

What do I need to do to get both the name and icon values of the element passed (cat) to the second table view controller?

Any help will be greatly appreciated!

Thanks

Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
hostedvn
  • 23
  • 4
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Apr 27 '15 at 02:14
  • Without knowing what `cat` is, it's impossible to say specifically why it's failing. (And note that the debugger display is unreliable -- you must either use NSLog or do `po cat` in the console.) – Hot Licks Apr 27 '15 at 02:20
  • How is this a duplicate? You guys worry more about this than trying to help answering questions. Sad :S – hostedvn Apr 28 '15 at 02:10

2 Answers2

0

Ok. Got your issue. You are using a weak property

@property (nonatomic,weak) NSDictionary *cat;

for your variable cat. It will be released just after you initialize it. Try using strong for it

@property (nonatomic,strong) NSDictionary *cat;

Hope this solves it

Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
0

This is how I solved the issue

NSString *myTitle = [cat objectForKey:@"name"];
NSString *myIcon = [cat objectForKey:@"icon"];
hostedvn
  • 23
  • 4