1

I have an iteration to process the _id value provided by JSON, and assign actions to each element in the list. My problem is that when I tap the element afterwards variable _id is always nil. Is there any way to assign the current iteration value of _id to each tap?

int i=0;
for (NSDictionary *item in json) {
    NSString *_id = [item objectForKey:@"_id"];

    //Main container
    //
    UIView *temp_container = [[UIView alloc] init];
    temp_container.frame = CGRectMake(0, i*76, 320, 75);
    temp_container.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:[^{ NSLog(@"id value: %@", _id); } copy] action:@selector(invoke)];
    tap.numberOfTapsRequired = 1;
    [temp_container addGestureRecognizer:tap];
    i++;
}

Here's the console output:

2014-08-26 18:17:32.511 appTwo[33519:60b] -[__NSArrayM invoke]: unrecognized selector sent to instance 0x91b6210
2014-08-26 18:17:32.515 appTwo[33519:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM invoke]: unrecognized selector sent to instance 0x91b6210'
denicio
  • 562
  • 1
  • 7
  • 22

0 Answers0