I am trying to add an action to my share button in navigation bar but I don't know how and where to define my "shareAction" method. To add share button, I have the following code in viewWillAppear :
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(shareAction:)];
self.navigationItem.rightBarButtonItem = shareButton;
in your implementation.m file
- (void) viewWillAppear
{
[super viewWillAppear:animated];
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(shareAction:)];
self.navigationItem.rightBarButtonItem = shareButton;
}
-(void)shareAction:(id)sender
{
NSLog(@"share action");
}
Swift
let shareBar: UIBarButtonItem = UIBarButtonItem.init(barButtonSystemItem:.Action, target: self, action: Selector("userDidTapShare"))
self.navigationItem.rightBarButtonItem = shareBar
func userDidTapShare() {
//Implementation goes here ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With