gpt4 book ai didi

ios - 禁用 RightBarButtonItems

转载 作者:行者123 更新时间:2023-12-01 17:25:59 30 4
gpt4 key购买 nike

我的 viewController 作为一个容器运行,并且有自己的 UINavigationBar。它不在导航 Controller 中。我的导航栏项目是这样设置的......

self.navigationItem.leftBarButtonItems = leftItems;
self.navigationItem.rightBarButtonItems = @[logout, settings];
[self.navBar setItems:@[self.navigationItem]];

在应用程序的各个点,此导航栏被锁定,直到用户完成任务。此代码段适用于切换导航栏中按钮的启用属性,但仅限于 leftBarButtonItems!为什么?
for(UIBarButtonItem *rightButton in self.navigationItem.rightBarButtonItems){
[rightButton setEnabled:!rightButton.enabled];
}
for(UIBarButtonItem *leftButton in self.navigationItem.leftBarButtonItems){
[leftButton setEnabled:!leftButton.enabled];
}

最佳答案

更新:

我创建了一个测试演示,效果很好。这是截图和代码,希望能给你一些帮助!

enter image description here
enter image description here

View Controller .h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property(nonatomic,strong) UINavigationItem * navItem;
@property(nonatomic,assign) IBOutlet UINavigationBar * navBar;

@end

View Controller .m
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];

UIBarButtonItem* barItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(barItemClicked:)];
UIBarButtonItem* barItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(barItemClicked:)];
UIBarButtonItem* barItem3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(barItemClicked:)];
UIBarButtonItem* barItem4 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(barItemClicked:)];
self.navItem = [[UINavigationItem alloc] init];
self.navItem.leftBarButtonItems = @[barItem1,barItem2];
self.navItem.rightBarButtonItems = @[barItem3,barItem4];
[self.navBar setItems:@[self.navItem]];

}
- (IBAction)anableSwitch:(id)sender{
UISegmentedControl * swith = (UISegmentedControl *)sender;

for(UIBarButtonItem *rightButton in self.navItem.leftBarButtonItems){
[rightButton setEnabled:(swith.selectedSegmentIndex == 0)];
}
for(UIBarButtonItem *leftButton in self.navItem.rightBarButtonItems){
[leftButton setEnabled:(swith.selectedSegmentIndex == 0)];
}
}
- (void)barItemClicked:(id)sender{
NSLog(@"barItemClicked");
}

关于ios - 禁用 RightBarButtonItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20013762/

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