问题
I am using UIImagePickerController to capture video from my app and i have set video maximum duration to 30 seconds. When that 30 seconds limit is reached. I get an alert with a message "maximum video recording limit reached" produced by UIImagePickerController and it stops capturing video.
What I want is that I want to respond to that alert that is generated automatically when 30 seconds limit is reached. I want to perform some action when "OK" button of that alert is pressed. I have implemented all the delegate methods of UIAlertView but it does come in any method when I press OK button.
Please help me how I can respond to that alert?
回答1:
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..)
回答2:
Set yourself as a delegate of your UIImagePickerController
, and implement the UIImagePickerControllerDelegate protocol. Specifically, the following method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)
回答3:
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
}
}
回答4:
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.");
}
}
来源:https://stackoverflow.com/questions/17541790/how-to-respond-to-uiimagepickercontroller-generated-uialertview