iPhoneProcessor
iPhoneProcessor

Reputation: 5110

UITextField issue in iOS 7

UIAlertView with UITextField not working in iOS 7. How to fix ?

Here is ScreenShot:

enter image description here Here is my code:

How can I get UITextFeield in UIAlertView in iOS7 ?

-(void)takeUserName
{
        mChangePlayerAlert = [[UIAlertView alloc] init];
        mChangePlayerAlert.title = title; 
        mChangePlayerAlert.message = @"\n";
        mChangePlayerAlert.delegate = self;
        [mChangePlayerAlert addButtonWithTitle:@"Save"];
        [mChangePlayerAlert addButtonWithTitle:@"Cancel"];

        CGRect frame;
        frame = CGRectMake(20, 45, 245, 27);//(200, 500, 400, 120);

        mTextFeild = [[UITextField alloc] initWithFrame:frame];
        mTextFeild.textColor = [UIColor blueColor];
        mTextFeild.borderStyle = UITextBorderStyleRoundedRect;

        mTextFeild.keyboardType = inType;//;
        mTextFeild.returnKeyType = UIReturnKeyDone;
        mTextFeild.autocorrectionType = UITextAutocorrectionTypeNo;
        mTextFeild.autocapitalizationType = UITextAutocapitalizationTypeNone;
        mTextFeild.delegate = self;

        [mChangePlayerAlert addSubview:mTextFeild];

        mTextFeild.delegate = self;
        [mTextFeild becomeFirstResponder];

        [mChangePlayerAlert show];
}

Upvotes: 0

Views: 1408

Answers (4)

Mavericks
Mavericks

Reputation: 524

Try this.

- (IBAction)showAlert:(id)sender
{
    UIAlertView *alertView = [[UIAlertView alloc] init];

    switch (((UIButton *)sender).tag)
    {
    // Default Alert View
    case 1001:

        alertView.title = @"Default Alert View";
        alertView.message = @"UIAlertViewStyleDefault";
        [alertView addButtonWithTitle:@"OK"];

        break;

    // Secure Alert View
    case 1002:

        alertView.title = @"Secure Alert View";
        alertView.message = @"UIAlertViewStyleSecureTextInput";
        alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
        [alertView addButtonWithTitle:@"OK"];
        [alertView addButtonWithTitle:@"Cancel"];

        break;

    // Plain Alert View
    case 1003:

        alertView.title = @"Plain Alert View";
        alertView.message = @"UIAlertViewStylePlainTextInput";
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        [alertView addButtonWithTitle:@"OK"];
        [alertView addButtonWithTitle:@"Cancel"];

        break;

    // Login ALert View
    case 1004:

        alertView.title = @"Login Alert View";
        alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        [alertView addButtonWithTitle:@"OK"];
        [alertView addButtonWithTitle:@"Cancel"];

        break;
   }

   [alertView show];
 }

Upvotes: 0

Vahan
Vahan

Reputation: 2186

You can use Custom Alert View Instead and add whatever content you want there: Custom iOS 7 Alert View

Upvotes: 2

Niru Mukund Shah
Niru Mukund Shah

Reputation: 4733

if above answer don't work for you try this

    [txtvwMessage setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

Generally iOS6 to iOS7 conversion looses the design controls. That's why autosizing concept is there to help you in conversion

Upvotes: 1

Léo Natan
Léo Natan

Reputation: 57040

You should not use a text view.

mChangePlayerAlert.alertViewStyle = UIAlertViewStylePlainTextInput;

To get the value later, use textFieldAtIndex: in the alert view delegate:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex != alertView.cancelButtonIndex)
    {
        NSString* text = [alertView textFieldAtIndex:0].text;

        ...
    }
}

Upvotes: 2

Related Questions