2011-06-30 18 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,真棒技巧:-) –

相關問題