2013-09-26 20 views
0

我有一個建立在Xcode的4.6和iOS 6。我使用它5的XCode輸入文本使用彈出在IOS 7

現在升級到iOS 7的應用程序,我有這樣的代碼完全上工作iOS 6.它會帶來一個帶有UITextField的彈出窗口。用戶可以輸入他們想要的任何文本並點擊確定。我把他們的文本放在UILabel中。

我的問題是,在iOS 7中,當我彈出這個彈出文本框,它不可編輯。觸摸它不會做任何事情。怎麼來的?

下面是代碼和截圖

// ************ 
// ENTER TEXT 
// ************ 

-(IBAction)insertText 
{ 
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Text \n" 
                message:@"\n\n Keep it short and sweet" 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"OK", nil]; 

    nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)]; 
    [nameField setBackgroundColor:[UIColor whiteColor]]; 
    [dialog addSubview:nameField]; 
    [dialog show]; 
} 

enter image description here

+0

以供將來參考 - http://stackoverflow.com/questions/6319417/whats-a-simple-way-to-get-a-text-input-popup-dialog-box-on-an-iphone –

回答

2

使用提供的API,而不是這個破解。不要添加您自己的文本字段(實際上從未支持),請將警報視圖的alertViewStyle設置爲UIAlertViewStylePlainTextInput。這會在警報視圖中爲您提供受支持的文本輸入字段。

+2

To完成此答案:黑客無法正常工作,因爲iOS 7不*支持向UIAlertView添加子視圖。但iOS 6確實如此。 –

+0

'UIAlertView'從不支持子視圖。它恰好適用於早期版本的iOS。它們是有區別的。 – rmaddy

+1

UIAlertView繼承自UIView。 UIView支持addSubview :.所以UIAlertView支持addSubview:只要它不阻止你使用它。當然,它沒有得到官方的支持(意思是由Apple記錄),但它得到了支持。 –