Adding TextField to UIAlertView

前端 未结 9 1358
不知归路
不知归路 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:20

    I'm using BlockAlertsAndActionSheets instead of the Apple components for AlertViews and ActionSheets as I prefer the blocks-approach. Also contains a BlockTextPromptAlertView in the source, which might be what you want. You can replace the images of that control to get the Apple-style back.

    Project on gitgub

    Tutorial which gets you started

    Example:

    - (IBAction)newFolder:(id)sender {
        id selfDelegate = self;
        UITextField                 *textField;
        BlockTextPromptAlertView    *alert = [BlockTextPromptAlertView  promptWithTitle :@"New Folder"
                                                                        message         :@"Please enter the name of the new folder!"
                                                                        textField       :&textField];
        [alert setCancelButtonWithTitle:@"Cancel" block:nil];
        [alert addButtonWithTitle:@"Okay" block:^{
            [selfDelegate createFolder:textField.text];
        }];
        [alert show];
    }
    
    - (void)createFolder:(NSString*)folderName {
        // do stuff
    }
    

提交回复
热议问题