菜鸟教程小白 发表于 2022-12-12 09:30:31

ios - 在 UIAlertView 试图查看两个文本字段。它显示文本字段数组iOS7的错误范围


                                            <p><p>您好,我正在尝试查看 <code>UIAlertView</code> 中的两个文本字段,但显示错误。我已经使用下面的代码来查看文本字段。</p>

<pre><code>- (void)viewDidLoad
{
    ;

    UIAlertView * alert = [ initWithTitle:@&#34;Hello!&#34;
                                                   message:@&#34;Please enter your details:&#34;
                                                    delegate:self
                                           cancelButtonTitle:@&#34;Continue&#34;
                                           otherButtonTitles:nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;

    UITextField * name = ;
    name.keyboardType = UIKeyboardTypeAlphabet;
    name.placeholder = @&#34;Enter your name&#34;;

    UITextField * phone = ;
    phone.keyboardType = UIKeyboardTypeNumberPad;
    phone.placeholder = @&#34;Enter your phone&#34;;

    ;
    ;
}
</code></pre>

<p>我已经使用上面的代码查看了两个文本文件,但我越来越喜欢了。 <strong>'textFieldIndex (1) 超出了文本字段数组的范围'</strong></p>

<p>请告诉我我在上面的代码中哪里做错了,请告诉我解决这个问题。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>查看 <code>UIAlertView.h</code> 文件</p>

<blockquote>
<p>/* Retrieve a text field at an index - raises NSRangeException when
textFieldIndex is out-of-bounds.   The field at index 0 will be the
first text field (the single field or the login field), the field at
index 1 will be the password field. */</p>
</blockquote>

<pre><code>- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
</code></pre>

<p>这样做:</p>

<pre><code>alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

UITextField * name = ;
name.keyboardType = UIKeyboardTypeAlphabet;
name.placeholder = @&#34;Enter your name&#34;;

UITextField * phone = ;
phone.secureTextEntry = NO;
phone.keyboardType = UIKeyboardTypeNumberPad;
phone.placeholder = @&#34;Enter your phone&#34;;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 UIAlertView 试图查看两个文本字段。它显示文本字段数组iOS7的错误范围,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/23193317/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/23193317/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 UIAlertView 试图查看两个文本字段。它显示文本字段数组iOS7的错误范围