gpt4 book ai didi

iphone - 如何隐藏导航栏中的两个右侧按钮之一

转载 作者:行者123 更新时间:2023-12-03 21:10:06 25 4
gpt4 key购买 nike

亲爱的大家,我在 TextView 顶部右侧的导航栏中实现了两个按钮:

UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 112, 44.5)];

// toolbar style is the default style

// create an array for the buttons

NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

// create a button to run the job
UIBarButtonItem *runButton = [[UIBarButtonItem alloc]
initWithTitle:@"RUN"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(runAs:)];
// Button style is the default style
[buttons addObject:runButton];
[runButton release];

// create a spacer between the buttons

UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];

// create a standard Edit/Done button with custom titles Edit/Save

self.editButtonItem.possibleTitles = [NSSet setWithObjects:@"Edit", @"Save", nil];
self.editButtonItem.title = @"Edit";
UIBarButtonItem *editButton = self.editButtonItem;
[buttons addObject:editButton];
[editButton release];

// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:YES];
[buttons release];

// place the toolbar into the navigation bar as Right Button item
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];

现在在编辑模式下,我想隐藏“运行”按钮,当“运行”按钮起作用时,我希望隐藏“编辑”按钮。有人可以建议我一种方法来做到这一点,而无需在编辑模式下重新定义按钮(就像后退/左按钮项目 setHidesBackButton:(BOOL)animated:(BOOL) 一样)或任何替代方法?多谢。

最佳答案

试试这个:

UIToolbar *toolbar = (UIToolbar *) self.navigationItem.rightBarButtonItem.customView;
UIBarButtonItem *runButton = (UIBarButtonItem *) [toolbar.items objectAtIndex: 0];
runButton.customView.hidden = YES;

关于iphone - 如何隐藏导航栏中的两个右侧按钮之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3712597/

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