2012-01-18 40 views
0

誰能告訴我如何顯示一個UIPickerView在另一個視圖中的值?我將值存儲在標籤中,但我必須在另一個視圖控制器中的按鈕中顯示此值。如何顯示從uipickerview到另一個視圖的選定值

+0

檢查這個線程 - http://stackoverflow.com/questions/5725580/how-to -get-selected-value-from-uipickerview – rishi 2012-01-18 07:05:33

+0

您是否試圖在另一個視圖中使用,比如您要查看還是在之前查看 – 2012-01-18 07:05:41

+0

是的,例如,當我點擊它時,第一個視圖中有按鈕。它將在第二視圖上移動,並從拾取器中選擇一些值。然後它將返回到第一視圖並在按鈕上顯示所選值。 – user1011291 2012-01-18 10:48:03

回答

0

當用戶關閉第二個視圖時,通常會將值數據存儲在模型中。當第一個視圖重新出現(或使用通知)時,它會從模型中讀取值。您的模型數據可能是plist或nsuserdefaults或核心數據等。

或者,您可以在創建第二個viewController並將其作爲第二個viewController上的屬性進行分配時創建對第一個viewController的引用。然後,在作用在第二的viewController有一個「路徑」到第一個的viewController:

第一的viewController將具有屬性,例如:

NSString *myStr; // in the header 
@property (nonatomic, retain) NSString *myStr; // in the header file 
@synthesize myStr; // in the implementation file 

第二的viewController將具有屬性,例如:

firstViewController *firstVC; // in the header 
@property (nonatomic, retain) firstViewController *firstVC; // in the header file 
@synthesize firstVC; // in the implementation file 

當您創建第二個的viewController,你會做這樣的事情:

secondViewController.firstVC = self; // in the implementation file 

然後,當你想更新第一的ViewController myStr中(從第二的viewController),你會做這樣的事情:

firstVC = @" my new value "; // in the implementation file 
相關問題