我正在尝试根据是否单击按钮来设置我的 UIBarbutton 项目标题,我认为我非常接近但不确定为什么它不起作用。我正在使用情节提要,barbuttons 名称/方法是“share1”,我所拥有的只是它在情节提要上连接到它,到目前为止,这是我的代码:
在我的 .h 中:
- (IBAction)share1:(id)sender;
在我的 .m 中:
#import "ViewController2.h"
@interface ViewController2 ()
@property (assign, nonatomic) BOOL sharepressed;
@end
@implementation ViewController2
- (IBAction)share1:(id)sender {
//i am trying to open a menu in this but that shouldn't affect the button.
if (self.sideMenu.isOpen) {
self.sharepressed = YES;
[self.sideMenu close];
}
else {
[self.sideMenu open];
}
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStyleBordered target:self action:@selector(share1:)];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (_sharepressed) {
self.navigationController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Hide" style:UIBarButtonItemStyleBordered target:self action:@selector(share1:)];
_sharepressed |= _sharepressed;
}
}
任何帮助将不胜感激。