How do I access the input from my text field in UIAlertController with objective c?

后端 未结 2 1273
时光取名叫无心
时光取名叫无心 2020-12-31 03:45

I\'m changing everything over from AlertView to AlertController, but I can\'t find anything online for objective c that retrieves what the user inputs in a text field for th

2条回答
  •  被撕碎了的回忆
    2020-12-31 04:16

    The UIAlertController has an array of textFields that are ordered by when you added them (the first one you added is index 0). Since it is a generic array, you will have to cast the result before accessing the text field.

    __weak UIAlertController *alertRef = alertController;
    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"Button Text"
                                             handler:^(UIAlertAction * action) {
                                                 // access text from text field
                                                 NSString *text = ((UITextField *)[alertRef.textFields objectAtIndex:0]).text;
                                             }];
    

提交回复
热议问题