我很困惑。我有一个 UITableView,当我单击一行时,它会执行一个带有新 UIViewController 的 pushViewController。我想将数据传递给这个新的 View Controller ,但我的对象为空。这是我使用的代码:
//TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyObject *myObject = [myArray objectAtIndex:indexPath.row];
SecondViewController *vc = [[SecondViewController alloc] init];
vc.newObject = myObject;
[self.navigationController pushViewController:vc animated:YES];
}
//SecondViewController.h
@property (nonatomic, strong) MyObject *newObject;
//SecondViewController.m
@implementation SecondViewController
@synthesize newObject = _newObject;
- (void)viewDidLoad {
NSLog(@"%@", _newObject); // nil
}
这很奇怪,因为我总是这样做,而且以前总是有效,我不明白为什么返回值为 null。
感谢您的帮助:)
最佳答案
检查您是否在其他地方重置 newObject
,例如 init
方法等。同时将 NSLog
更改为 NSLog(@"%@", self.newObject);
并重试。
关于iphone - 在 UIViewController 之间传递数据时获取 (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12845893/