2011-06-17 21 views
0

我開始學習在應用程序中使用UIPicker。我想要做的是,當用戶點擊郵政編碼文本框時,我想讓uipicker彈出並顯示可用的郵編列表。就像在c#或VB.net中的下拉菜單一樣。我必須創建一個新視圖並將uipicker放置在那裏嗎? 謝謝UIPicker特定問題(iphone)

回答

1

爲了有一個UIPickerView出現在您的應用程序,你不需要額外的視圖。

假設你是一個UIViewController:

@interface MyController : UIViewController { 
    UIPickerView* mPicker; 
} 
-(void)showPicker; 
-(void)hidePicker; 
@end 

-(void)showPicker { 
    [self.view addSubview:mPicker]; 
    mPicker.center = CGPoint // set out of sight 

    [UIView beginAnimations:nil context:nil]; 
    // do your transformations 
    [UIView commitAnimations]; 
} 

-(void)hidePicker { 
    // do your exit animations 
} 

您還可以添加一個委託函數的第二動畫從上海華刪除mPicker。

欲瞭解更多信息,看看在UIView Reference

2
  1. 您需要放置文本框的視圖。不管它是否需要成爲新視圖或舊視圖 - 只需將文本框放入所需視圖即可。

  2. 確保

    textField.inputView = yourPickerView; 
    
+2

+1您可能還需要添加一個'inputAccessoryView'來關閉選取器。 –