I have this int I am declaring in my .h file like this:
@interface searchResultsViewController : UIViewController {
int selectedEvent;
}
@property (nonatomic) int selectedEvent;
It holds the selected row in a table. When a user taps the row, the int is set here:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedEvent = [indexPath row];
}
And then passed onto this method here:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"detailView"]) {
NSLog(@"%@", self.selectedEvent);
}
}
However, in that method, the NSLog returns null. I am not editing the int in any other part of the file and I am @synthesizeing it at the top of the file. I’m not exactly sure what is going on, could someone please explain?
Thanks
An
intis not an object, so you when you use%@, the computer looks for something at the memory address of whatever theintis set to, and when it finds nothing, returnsnull. To log anintuse%d. Like this:Other valid types are
%@for an object (NSString,NSDictionary,NSArray, etc.),%ffordouble,%uforunsigned int, etc.More info here.