gpt4 book ai didi

ios - 如何使用 Xcode 在导航栏中添加一个共享按钮的 Action

转载 作者:可可西里 更新时间:2023-11-01 03:25:21 28 4
gpt4 key购买 nike

我正在尝试向导航栏中的共享按钮添加一个操作,但我不知道如何以及在何处定义我的“shareAction”方法。要添加分享按钮,我在 viewWillAppear 中有以下代码:

UIBarButtonItem *shareButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(shareAction:)];
self.navigationItem.rightBarButtonItem = shareButton;

最佳答案

在你的implementation.m文件中

- (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");
}

关于ios - 如何使用 Xcode 在导航栏中添加一个共享按钮的 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24991713/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com