2013-12-11 22 views
0

UIAlertview當我點擊文本框時不添加UIDatePicker?UIAlertview當我點擊文本框時不添加UIDatePicker?

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Preferences" 
               message:@"\n\n\n\n\n\n\n" 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"OK", nil]; 
    pickerView=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,40,246,150)]; 
    pickerView.datePickerMode=UIDatePickerModeDate; 
    [alert addSubview:pickerView]; 
    [alert show]; 
} 
+0

它只顯示在alertview裏面的alertview而不是datepicker – MAC113

回答

0

在iOS7 UIAlertView's視圖層次結構已經改變,所以現在你不能任何視圖添加到UIAleartView

+0

我現在能做什麼? – MAC113

+0

您可以創建自定義Aleartview或搜索自定義aleartview –

1

的iOS 7不支持添加子視圖的層次了。這就是我寫信SDCAlertView的原因。它添加了一個contentView屬性,您可以使用該屬性將任何其他視圖添加到警報中。

0

試試這個代碼

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Hello" 
    message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Stamp", nil]; 
    UIDatePicker *pickerView=[[UIDatePicker alloc]initWithFrame:CGRectMake(0,40,246,150)]; 
    pickerView.datePickerMode=UIDatePickerModeDate; 
    myAlertView.tag=101; 
    [myAlertView show]; 
    UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10, myAlertView.bounds.size.height, 320, 216)]; 
    // Add picker to alert 
    [myAlertView addSubview:picker]; 
    // Adjust the alerts bounds 
    myAlertView.bounds = CGRectMake(0, 0, 320 + 20, myAlertView.bounds.size.height + 216 + 20); 
    [myAlertView release]; 
+1

不起作用。 'UIAlertView'上的'addSubview:'在iOS 7中完全不會做任何事情。 –

+0

-1因爲這是不正確的,因爲它基於https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView .html你不允許修改'UIAlertView'層次結構。 – Popeye

0

遺憾的是蘋果公司不會允許您添加子視圖或修改視圖層次結構。請參閱https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html

UIAlertView類旨在按原樣使用,不支持子類。該類的視圖層次結構是私有的,不能修改。

而看到https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIAlertView.html#//apple_ref/doc/uid/TP40012857-UIAlertView爲:警報的

外觀圖

無法自定義的警報視圖的外觀。

逆着這些都會讓你的應用程序被拒絕在蘋果的審查過程 - 所以我會回去看看你的你的應用程序的設計。

相關問題