簡體   English   中英

如何在iPad中顯示UIDatePicker?

[英]how to show UIDatePicker in iPad?

我在iPhone中實現了UIDatePicker ,它可以正常工作。

我在iPad上嘗試過的相同代碼,但沒有顯示UIDatePicker

我讀到某個地方需要用UIPopOverController進行顯示,並找到鏈接,但未顯示正確的代碼。

我不能為此做一個單獨的XIB。 我必須通過代碼本身來實現。 我的是IOS5。

我使用以下代碼:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.tag == 1)
    {
            [self showDatePickerIniPad];
      }
}
   -(void)showDatePickerIniPad
 {
     UIViewController *popoverContent = [[UIViewController alloc] init];
     UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     popoverView.backgroundColor = [UIColor whiteColor];
     datePicker.frame = CGRectMake(0, 0, 320, 300);
     [popoverView addSubview:datePicker];
     popoverContent.view = popoverView;
     popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

     UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
     [popoverController presentPopoverFromRect:CGRectZero inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

     txt_FromDate.inputView = datePicker;
 }

如果希望在單擊文本框時顯示彈出框,則使用正確的方法- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 。問題是這是textField的Delegate方法,因此您應該包括UITextFieldDelegate在.h文件中的界面中

@interface myViewController : UIViewController<UITextFieldDelegate>{

並像這樣設置您的代理人文本字段

self.yourTextField.delegate = self;

那應該解決您的問題。

由於您的問題更多是基於學習的問題,而不是特定的疑問或問題,因此我發布了教程鏈接。 這2個教程應該可以解決您的問題-

UIPickerView基礎

UIDateView組件

更新:還檢查來自stackoverlfow本身的這些高度相關的鏈接-

iPad上UIActionSheet中的UIDatePicker

https://stackoverflow.com/questions/5830585/uidatepicker-inside-uiactionsheet-ipad

iPad上UIDatePickerModeDateAndTime模式下的空白UIDatePicker

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM