第一视图: 由textview(用户输入)和&组成。按钮(按此按钮将你带到第二个视图)
第二视图: 由标签
组成我希望标签显示用户在第一个视图中写的内容。
答案 0 :(得分:2)
我认为您在按钮Click时创建第二个视图。只需将textView(textView.text
)的数据传递给第二个视图的构造函数即可。然后,您可以使用viewDidLoad()
方法将数据设置为标签。
答案 1 :(得分:1)
在SecondViewController
中的.h文件中NSString *strUserInput;
在seconviewcontroller中创建以下功能
-(void)setUserInput:(NSString *)strEntered{
strUserInput=strEntered;
}
现在在第一个视图中,控制器是这样的:
SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];
现在,在secondViewController中,viewWillAppear方法写下这个。
-(void)viewWillAppear:(BOOL)animated{
lblUserInput.text = strUserInput;
}
我手写这个时请检查拼写错误。希望这有帮助。
如果您没有使用navigationContoller,那么您可以这样做。
SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[objSecond viewWillAppear:YES];
[self.view addSubview:objSecond];
[objSecond release];