2008-12-17 69 views
4

我正在設置一個帶有文本字段的提醒,以便玩家可以輸入他們的名字以獲得高分。遊戲以橫向模式爲導向,但當我打電話來顯示警報時,在縱向模式下彈出兩個鍵盤,一個橫向模式和一個橫向模式(這是橫向大小)。下面的代碼我使用設置警告對話框:在iPhone提醒對話框上彈出多個鍵盤?

UIAlertView* dialog = [[[UIAlertView alloc] init] retain]; 
[dialog setDelegate:self]; 
[dialog setTitle:@"Enter Name"]; 
[dialog setMessage:@" "]; 
[dialog addButtonWithTitle:@"Cancel"]; 
[dialog addButtonWithTitle:@"OK"]; 
[dialog addTextFieldWithValue:@"name" label:@""]; 
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0); 
[dialog setTransform: moveUp]; 
[dialog show]; 
[dialog release]; 

如何使警報顯示在橫向和防止它顯示兩個鍵盤?

感謝, 本

+0

你有這個截圖嗎? (只是爲了好玩!) – squelart 2009-01-04 21:31:05

回答

2

對於那些誰可以照顧,這裏是一個有效的解決方案,它正常工作在橫向模式下:

UIAlertView* dialog = [[[UIAlertView alloc] init] retain]; 
[dialog setDelegate:self]; 
[dialog setTitle:@"Enter Name"]; 
[dialog setMessage:@" "]; 
[dialog addButtonWithTitle:@"Cancel"]; 
[dialog addButtonWithTitle:@"OK"]; 

nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)]; 
[nameField setBackgroundColor:[UIColor whiteColor]]; 
[dialog addSubview:nameField]; 
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0); 
[dialog setTransform: moveUp]; 
[dialog show]; 
[dialog release]; 
[nameField release]; 

確保您創建的UITextField *名稱字段;在您的.h文件中,然後您可以獲取用戶輸入的文本: inputText = [nameField text];

在 - (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex方法中。

+2

我看到你做了dialog = [[[UIAlertView alloc] init] retain]和[dialog release]。 alloc和retain都應該與一個版本匹配,所以我認爲這是一個泄漏(除非你的程序中有其他版本)。在任何情況下,'保留'似乎都是不必要的,因爲alloc也是這樣。 – squelart 2009-01-04 21:38:57