Adding TextField to UIAlertView

前端 未结 9 1362
不知归路
不知归路 2021-02-12 12:38

I need to add a TextField to an UIAlertView. I understand that apple discourage this approach. So is there any library that i could make use of to add

9条回答
  •  [愿得一人]
    2021-02-12 13:02

    first of All Add UIAlertViewDelegate into ViewController.h File like

    #import 
    
    @interface UIViewController : UITableViewController
    
    @end
    

    and than Add Below Code where you wants to alert Display,

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
                                                message:@"Message"
                                               delegate:self
                                      cancelButtonTitle:@"Done"
                                      otherButtonTitles:nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert show];
    

    and it's delegate method which returns what input of UItextField

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    NSLog(@"%@", [alertView textFieldAtIndex:0].text);
    }
    

提交回复
热议问题