2011-06-30 19 views
0

首先视图使用数据: 由一个TextView的(用户输入)&按钮(这个按钮按需要u到第二视图)iPhone发展 - 从另一种观点认为

第二个视图: 由标签

我希望标签显示用户在第一个视图中写的内容。

回答

1

在SecondViewController

NSString *strUserInput; 

在seconviewcontroller

-(void)setUserInput:(NSString *)strEntered{ 
    strUserInput=strEntered; 
} 

现在,在第一个视图控制器做这样借此在.h文件中进行以下功能:

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil]; 

[objSecond setUserInput:txtUserInput.text]; 
[self.navigationController pushViewController:objSecond animated:YES]; 
[objSecond release]; 

现在, secondViewController viewWillAppear Method写这个。

-(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]; 
+0

thnx :)但推视图只用于基于导航的应用程序,如果我是基于窗口的应用程序会怎么样? –

+0

我编辑了我的答案。希望能帮助你。 – Deeps

2

我想你是在buttonClick时创建第二个视图。只需将textView(textView.text)的数据传递给第二个视图的构造函数即可。然后您可以在viewDidLoad()方法中将数据设置为标签。

+0

我喜欢这个asnwer! :D –

+0

@Onuray,真棒技巧:-) –

相关问题