我正在使用 Objective-C 中的按钮点击创建一个我需要在视图之间传递数据的应用程序。
我创建了 ViewController.m 到传递和 DetailController.m 到获取 ... < / p>
ViewController.m:
- (IBAction)btnSubmit:(id)sender {
NSString *name = [txtName text];
DetailController *view2 = [[[DetailController alloc]
initWithNibName:nil bundle:nil] autorelease];
[self presentViewController:view2 animated:NO completion:NULL];
}
DetailController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
lblResult.text = [self.detailItem description];
}
我无法理解为什么我无法将名称值传递给其他视图
答案 0 :(得分:6)
你忘了添加这一行:
view2.detailItem = name;
(IBAction)btnSubmit:(id)sender {
NSString *name = [txtName text];
DetailController *view2 = [[[DetailController alloc]
initWithNibName:nil bundle:nil] autorelease];
view2.detailItem = name;
[self presentViewController:view2 animated:NO completion:NULL];
}
答案 1 :(得分:1)
DetailController *view2 = [[[DetailController alloc]
initWithNibName:nil bundle:nil] autorelease];
view2.detailItem = self.yourValue;
[self presentViewController:view2 animated:NO completion:NULL];