我需要在两个 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/