2011-04-05 53 views
2

我有一個兩難的問題,我有兩個UIPickerViews「顯示」兩個不同的視圖加載時。我從一個UIPickerView開始,並能夠通過在ViewController中加載數組和所有其他UIPickerView操作來啓動並運行。多個UIPickerViews

我認爲這將會像爲新的UIPickerView複製/粘貼相同的方法一樣簡單,只是更改變量名稱,也在同一個UIViewController內。

問題是 - 兩個UIPickerView在下拉列表中顯示相同的數據集?我在這裏只是錯過了一些明顯的東西?

更新下面

我做了所有四種方法下面和現在的應用程序崩潰,一旦「下一步」視圖被加載?這看起來正確嗎?

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView 

- (NSInteger)thePickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 

- (NSString *)thePickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 

- (void)thePickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
+0

是的方法看起來不錯,你的崩潰是由於別的東西。嘗試調試器!在運行 - >調試器。或發佈更多的代碼。 – ThomasRS 2011-04-05 01:36:02

回答

13

是的,你是,你必須使用UIPickerView參數來確定哪些選擇器視圖實際上是要求數據 - 因爲您設置了採摘到同一數據源。

-(void)numberOfComponentInPickerView:(UIPickerView*)thePickerView { 
    if(thePickerView == firstPickerView) { 
     // return number of components in first picker  
    } else if(thePickerView == secondPickerView) {  
     // return number of components in second picker  
    } else { 
     assert(NO); 
    } 
} 

// repeat for all other delegate/datasource methods 
+0

我看不懂!更新您的帖子,而不是.. – ThomasRS 2011-04-05 01:26:35

+0

洛麗雅,有一個艱難的時間與格式 - 給我一分鐘! – timw07 2011-04-05 01:29:18

+0

更新,謝謝我想知道如果我需要初始化「thePickerView」?如果是這樣 - 我應該將IB中的UIPickerViews與「thePickerView」和「secondPickerView」關聯起來嗎? – timw07 2011-04-05 02:10:44