How to respond to UIImagePickerController Generated UIAlertView

别来无恙 提交于 2019-12-04 22:02:22

You can't use all those delegate methods because you didn't initiate the UIAlertView so you can't set his delegate...

The only thing I can think about is to do somethong like listening to the UIWindowDidBecomeVisibleNotification to detect when an alert is shown and to the UIWindowDidBecomeHiddenNotification notification to detect when it disappears.

You should know that those notification will fire for all kind of components that uses their own UIWindow such as UIActionSheet or the keyboard, so you need to make sure this is the right one (maybe check to see if there is a UIAlertView in one of the subviews..)

Set yourself as a delegate of your UIImagePickerController, and implement the UIImagePickerControllerDelegate protocol. Specifically, the following method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)

Use UIAlertViewDelegateProtocol

Form docs

alertView:clickedButtonAtIndex:

Sent to the delegate when the user clicks a button on an alert view.

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex Parameters alertView The alert view containing the button. buttonIndex The index of the button that was clicked. The button indices start at 0. Discussion The receiver is automatically dismissed after this method is invoked.

Availability Available in iOS 2.0 and later. Declared In UIAlertView.h

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
    {
        // do stuff for button index 0,ie cancel button and sthe same for other button  indeces
    }
}

Please refer this tutorials : http://mobile.tutsplus.com/tutorials/iphone/uialertview/ you can get more ideal about this :

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                  message:@"This is your first UIAlertview message."
                                                 delegate:self
                                        cancelButtonTitle:@"Button 1"
                                        otherButtonTitles:@"Button 2", @"Button 3", nil];
[message show];


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Button 1"])
    {
        NSLog(@"Button 1 was selected.");
    }
    else if([title isEqualToString:@"Button 2"])
    {
        NSLog(@"Button 2 was selected.");
    }
    else if([title isEqualToString:@"Button 3"])
    {
        NSLog(@"Button 3 was selected.");
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!