我知道這個問題是非常基本的,但作爲一個java程序員,我很困惑爲什麼這個值變成了零?我有UITableView,我試圖將選定的行號發送到目標UIViewController。然而,這是即使在prepareForSegue
爲什麼NSNumber從一個函數變爲零到另一個函數?
NSNumber* val;
/*segue*/
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
//Perform a segue.
[self performSegueWithIdentifier:@"toInfo"
sender:[items objectAtIndex:indexPath.row]];
val = [[NSNumber alloc] init];
val = [NSNumber numberWithInt:indexPath.row];
NSLog(@"val111 === %@",val); >>>Here prints 2
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// [self performSegueWithIdentifier:@"toInfo" sender:sender];
NSLog(@"inside segue");
NSLog(@"val222 === %@",val); >>> Here prints null
InfoViewController *vc = [segue destinationViewController];
vc.journeyId = val;
}
因爲您在執行完畢後爲val指定了值valueIdIndntifier – 2014-09-29 04:50:33