سؤال

I have a global variable that im writing into from a table view, in the:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

i am setting the global eventID variable (which is an [NSNumber numberWithInt]) to the row being selected:

[[GlobalData sharedGlobalData]setEventId:[NSNumber numberWithInt:indexPath.row]];

I'm then using this variable to access an index in an array. However i'm getting odd results, when i NSLog the eventID variable it's appearing a "0", which is correct, im selecting the first row in the table.

However when i use the eventID variable as the object at index:

event = [[venue venueEventList]objectAtIndex:[[GlobalData sharedGlobalData]eventId]];

The app is crashing with the following error:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 163756576 beyond bounds [0 .. 4]' * First throw call stack: (0x1b8f012 0x1600e7e 0x1b310b4 0x5139 0x6261c7 0x626232 0x6264da 0x63d8e5 0x63d9cb 0x63dc76 0x63dd71 0x63e89b 0x63ee93 0xf3e83f7 0x63ea88 0x99ae63 0x98cb99 0x626dd2 0xf3e012c 0x32343 0x5f4285 0x5f44ed 0xffe5b3 0x1b4e376 0x1b4de06 0x1b35a82 0x1b34f44 0x1b34e1b 0x19d87e3 0x19d8668 0x544ffc 0x29cd 0x28f5)

Surely the eventID variable is 0 so why is the array being accessed at index 163756576

any help would be great!

هل كانت مفيدة؟

المحلول

Ok obviously a completely stupid question, i clearly again did not sleep enough, i wasn't getting the int value of the nsnumber and therefore was getting the long value. problem solved by the following:

[variable intValue];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top