2011-07-18 7 views
0

に、彼らはその後、「OK」または「キャンセル」できるURLを入力することができなければなりません。のiOS/UITextFieldにはUIAlertView

どうすればよいですか?

もちろん、私は、テキストフィールドと2つのボタンを含む新しいビューを作成することができます。しかし、これはオーバーコーディングのようです。私が見つけた

一つの解決策はUIAlertViewへのUITextFieldを 'ハッキング' が含ま:http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html

(EDIT:ベター - http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html#post10643

これは本当に醜いです。それは明らかにハックです。

誰もがよりよい解決策(または同じ溶液パスのより良い実装)を提供することはできますか?

+0

のErmは 'textfield.text'or私は右のあなたを理解していないのですか? –

+0

申し訳ありませんが、私の悪い言葉遣い。私は質問を編集しました。 –

+0

ここでも説明しますhttp://stackoverflow.com/questions/376104/uitextfield-in-uialertview-on-iphone-how-to-make-it-responsive – neoneye

答えて

2

OKを、ここでの結果です。 SOの検索に「UITextFieldのUIAlertView」に入れてまず

は、ヒットの数十を返します。

それは、これを行うための方法がある判明Need new way to add a UITextField to a UIAlertViewが、それはプライベートAPIであります:| http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html
https://github.com/josecastillo/EGOTextFieldAlertView/
How to move the buttons in a UIAlertView to make room for an inserted UITextField?
^ MrGandoの答えがきちんとある
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
Getting text from UIAlertView

のみ適切な解決策:

は、ほとんどすべての他の解決策は醜いですUIAlertViewを、ハッキング関係します私は見つけた(つまり、UIViewから最初からコーディングする)ここにあります:https://github.com/TomSwift/TSAlertView

これは、それが取るすべてである:

- (IBAction) importTap 
{ 
    TSAlertView* av = [[[TSAlertView alloc] init] autorelease]; 
    av.title = @"Enter URL"; 
    av.message = @""; 

    [av addButtonWithTitle: @"Ok"]; 
    [av addButtonWithTitle: @"Cancel"]; 


    av.style = TSAlertViewStyleInput; 
    av.buttonLayout = TSAlertViewButtonLayoutNormal; 
    av.delegate = self; 

    av.inputTextField.text = @"http://"; 

    [av show]; 
} 

// after animation 
- (void) alertView: (TSAlertView *) alertView 
didDismissWithButtonIndex: (NSInteger) buttonIndex 
{ 
    // cancel 
    if(buttonIndex == 1) 
     return; 

    LOG(@"Got: %@", alertView.inputTextField.text); 
} 

とプレスト!

enter image description here

+2

実際、 'UIAlertView'sのテキストフィールドはiOSでサポートされますしかし、これは唯一の注意点です、iOS 5 – Espresso

+1

:実際、UIAlertViewsのテキストフィールドはiOS 5でサポートされます。http://mobile.tutsplus.com/tutorials/iphone/ios-5-sdk-uialertview-text -input-and-validation / – OscarTheGrouch

0

私は「XIBからUIAlertViewにするUITextFieldを追加する方法」のトピックに私のブログで記事を作成しました。 XIBを使用して追加することは、純粋なコーディングより簡単です。カスタマイズされた小さなビューであれば何でも追加できます。次に、1行のコードを使用して小さなビューをAlertViewに追加します。次のリンクを参照してください。 ...が、なぜあなたが使用していない

http://creiapp.blogspot.com/2011/08/how-to-add-uitextfield-to-uialertview.html