iphone - 数据不在 ViewController 之间传递

标签 iphone objective-c ios uiviewcontroller

我需要在两个 View Controller 之间传递数据。这是我的代码。

第一个 View Controller

-(void)editBotton {

    Carttable *second=[[Carttable alloc]init];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:second];
    nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;

    [self.navigationController pushViewController:second animated:YES];

    NSString *temp=titlela.text;//titlela is UILabel

    NSLog(@"%@",temp);
    self.cart=second;
    cart.cnftitle=temp;
}

在我的 cartable view controller.h 中

@property(nonatomic,retain)NSString *cnftitle;

我也合成了

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%@",cnftitle);
}

一个 NSlog 在标签中打印我的文本,而另一个打印为 NULL....

我错过了什么吗?

最佳答案

您在 View 加载后分配值。

将您的任务移到 pushViewController 之前:(因为这是加载 View 的位置)

关于iphone - 数据不在 ViewController 之间传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11657021/

相关文章:

iPhone 4 根据 GPS 纬度和一年中的某一天以编程方式计算日持续时间

iphone - 从 UIImagePicker 相机拍摄后如何裁剪图像?

iphone - 如何从Objective-c中的另一个方法调用手势滑动方法

ios - 检索 iOS 项目中的分支名称

ios - TableViewCellSeparator 不显示

iphone - AVCaptureSession 指定自定义分辨率

iphone - 如何从 iOS 文件中存储的数据中解码多个对象

ios - 为什么弱强舞会保持循环?

ios - 如何在.h 文件中的辅助@interface 中调用方法

html - 将 HTML 文本分配给 NSAttributedString 会在全局队列上抛出 EXC_BAD_ACESS