3
votes

I have overridden the -inputAccessoryView: method in a UIViewController which returns a view which is displayed on top of the keyboard which is shown while editing a UITextField on the viewController's view.

-(UIView *)inputAccessoryView;

I am also presenting a UIAlertController from the viewController.

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Save Profile" message:@"You have made changes to your profile. Do you want to save them?" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //Code to save the profile.
    }]];
[self presentViewController:alert animated:YES completion:nil];

As you can see I have not added any textField to the UIAlertController.

Weirdly, the inputAcessoryView turns up at the bottom of the screen when the UIAlertController is presented.

Is this a bug, or have I overlooked something?

4
I am facing the same issue.GoGreen

4 Answers

1
votes

Rename your input accessory view to something other than inputAccessoryView. e.g. keyboardaccessoryView.

Then add the following line

self.m_textFieldName.inputAccessoryView = [self keyboardInputAccessoryView];

This solved the problem for me.

0
votes

Do not use the name 'inputAccessoryView'

This will fix..!

    - (UIView *)CustominputAccessoryView {
    if (!keyboardinputAccessoryView) {
        CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0);
        keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
        keyboardinputAccessoryView.backgroundColor = [UIColor  colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6];
        UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom];
        compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0);
        [compButton setTitle: @"Done" forState:UIControlStateNormal];
        compButton.titleLabel.textColor = [UIColor blueColor];
        [compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
        [compButton addTarget:self action:@selector(completeCurrentWord:)
             forControlEvents:UIControlEventTouchUpInside];
        [keyboardinputAccessoryView addSubview:compButton];
    }
    return keyboardinputAccessoryView;
}

keyboardinputAccessoryView is just a UIView

@property (readonly, retain) UIView *keyboardinputAccessoryView;

then make 'CustominputAccessoryView' as inputAccessoryView of your textField

- (void)textFieldDidBeginEditing:(UITextField *)textField {
 textField.inputAccessoryView = [self CustominputAccessoryView];
}
0
votes

Got the same problem, you can try

textFirld.resignFirstResponder()

Before you present the AlertViewController.

It works for me.

-1
votes

You have property for UITextField like inputAccessoryView so it is over riding it. If possible

Just change the name of the view from

-(UIView *)inputAccessoryView;

to some name

-(UIView *)alertDisplayView;

This will fix..! Exactly I don't no why u have taken view with name inputAccessoryView..!

Hope it helps you..!