iphone - 在 UIViewController 之间传递数据时获取 (null)

标签 iphone objective-c ios

我很困惑。我有一个 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/

相关文章:

ios - UITableViewCell 中的 UICollectionView

objective-c - 简单数组的问题 - Cocoa

iphone - 如何在iPhone中仅使用开发证书生成iPA文件?

iphone - 录制红色状态栏上的自定义文本

php - 如何从ios正确上传大文件?

ios - 使用 spritekit 和 swift 在游戏中实现短声音

iphone - Redis 对比iOS 应用程序中推送通知的 Web 服务

ios - 删除部分的最后一行后,应用程序崩溃

iphone - 在 iPhone 上运行我的应用程序时图像模糊

iphone - 视网膜显示图像问题