gpt4 book ai didi

ios - 在 UINavigationBar 中隐藏或禁用 UIBarButtonItem

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:41 24 4
gpt4 key购买 nike

我正在展示一个带有模态转场的 UIViewController。这个 UIViewController 继承了一个 UINavigationBar,我在导航栏的左侧设置了一个 UIBarButtonItem:

HELP ME!!!

我的问题是,当调用呈现的 UIViewController 的 viewWillAppear 方法时,我试图隐藏 UIBarButtonItem,但 UIBarButtonItem 总是出现。我已经为 UIViewController 声明了一个 UIBarButtonItem,名为 myCancelButton,并且我在 Interface Builder 中引用了它。

这是我到目前为止尝试过的方法(所有这些都不起作用):

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.backBarButtonItem = nil;
self.myCancelButton = nil;

NSMutableArray *barButtonItems = [self.navigationItem.leftBarButtonItems mutableCopy];
[barButtonItems removeObject:self.myCancelButton];
self.navigationItem.leftBarButtonItems = barButtonItems;

[self.navigationItem.leftBarButtonItems delete:self.myCancelButton];

self.navigationController.navigationItem.leftBarButtonItem = nil;
barButtonItems = [self.navigationController.navigationItem.leftBarButtonItems mutableCopy];
[barButtonItems removeObject:self.myCancelButton];
self.navigationController.navigationItem.leftBarButtonItems = barButtonItems;

[self.navigationController.navigationItem.leftBarButtonItems delete:self.myCancelButton];

[self.myCancelButton setWidth:0.01];

self.navigationItem.hidesBackButton = TRUE;

//Even setting enabled to false doesn't work:
[self.myCancelButton setEnabled:FALSE];
}

最佳答案

这应该有效。

[self.navigationItem setHidesBackButton:YES animated:YES];

关于ios - 在 UINavigationBar 中隐藏或禁用 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15237922/

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