I create a Cocoa Touch Class, called MyPLayer
MyPLayer.h
@interface MyPLayer : NSObject<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
and inside there I create a picker view.
MyPlayer.m
@implementation MyPLayer
SINGLETON_GCD(MyPLayer);
In the method to start the video capture:
+ (void)startCaptureVideoFromViewController:(UIViewController *)controller videoUploadProgressionHandler:(VideoUploadProgressionBlock)videoUploadProgressionBlock videoSavedHandler:(VideoSavedBlock)videoSavedBlock videoCanceledHandler:(VideoWasCanceledBlock)videoCanceledBlock captureFailedHandler:(FailDetailsBlock)failBlock {
id <UIImagePickerControllerDelegate, UINavigationControllerDelegate> delegate = [MyPlayer sharedInstance];
And in the UIPickerViewController inside my library I set the delegate
picker.delegate = delegate;
After define the picker.mediaTypes and picker.cameraDevice, I create a UIToolbar, and inside I create a button.
UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, [dadosUsuario doubleForKey:@"toolBarHeigh"]-54, [dadosUsuario doubleForKey:@"toolBarWidth"], 55)];
toolBar.barStyle = UIBarStyleBlackOpaque;
NSArray *items=[NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(shootVideo)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
nil];
[toolBar setItems:items];
On my UIViewController I call my MyPlayer, call the method the show the UIPickerView. The overlay appears, also the button. But where can I create the method to match the @selector on the UIToolbar?
All the UIPicker Delegate methods are inside MyPLayer, but I can't fire the UIBarItem. I think this is because the delegate or something else.
When I declare all this code (picker view , uibaritem and selector method)in a regular UIViewController, this works fine.
Following this post
UIBarButtonItem: target-action not working?
The only way that I found to work was create a UIButton, instead of a UIToolbar / UIBarButtonItem.