2008-11-12 27 views

回答

7

我發現了一個解決方案: http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html

這裏是爲我工作的代碼。

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 

CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0); 
[myAlertView setTransform:myTransform]; 

[myTextField setBackgroundColor:[UIColor whiteColor]]; 
[myAlertView addSubview:myTextField]; 
[myAlertView show]; 
[myAlertView release]; 
4

您需要創建彈出窗口(UIAlertView)並將UITextField(或任何您想使用的組件)添加到它作爲子視圖。 UIAlertView不會爲您添加的組件自動調整大小,因此您必須通過向其中添加文本來將它的那部分一起破解。該文本將增加彈出窗口的高度,並提供您不會添加太多被您的組件隱藏的內容。

1

將此函數添加到您的代碼中,在顯示警報之前調用它。

  • (無效)willPresentAlertView:(UIAlertView中*)alertView { alertView.frame = CGRectMake(X,Y,寬度,heigth); }
1

一種調整您的UIAlertView中提示...

由於米倫Milkovski上/下,如果你設置了UIAlertView中的委託寫道:

UIAlertView* theAlert = [[UIAlertView alloc] initWithTitle:@"Lah" 
                message:@"dee dah" 
                delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:nil]; 
//NSLog(@"Pre Show: alert frame x,y: %f,%f, alert frame width,height: %f,%f", theAlert.frame.origin.x,theAlert.frame.origin.y, theAlert.frame.size.width, theAlert.frame.size.height); 
[retrievingListAlert show]; 

然後,您可以修改通過定義以下UIAlertView回調(在委託類中 - 在這種情況下,因爲我們使用self,與創建UIAlertView的位置相同)的UIAlertView框架:

(void)willPresentAlertView:(UIAlertView *)alertView { 
    //NSLog(@"willPresentAlertView: alert frame midx,midy: %f,%f, alert frame width,height: %f,%f", alertView.frame.origin.x, alertView.frame.origin.y, alertView.frame.size.width, alertView.frame.size.height); 
    alertView.frame = CGRectMake(x, y, width, heigth); 
} 

我發現在其他時間設置幀不起作用。看起來show功能修改框架,大概是在自動調整內容的同時。