gpt4 book ai didi

iphone - 设置导航 Controller 的工具栏项

转载 作者:行者123 更新时间:2023-12-03 18:38:00 24 4
gpt4 key购买 nike

我正在尝试使用以下调用为 navigationController 设置项目

NSArray *items = [NSArray arrayWithObjects: shareButton, nil];
[self.navigationController.toolbar setItems:items animated:NO];

这不会向工具栏添加任何内容。

我可以使用隐藏和显示工具栏

[self.navigationController setToolbarHidden:NO];

但无法让项目出现。

如何设置项目。 ?

更新:

enter image description here

最佳答案

工具栏是只读属性。您可以这样设置工具栏:

toolbar The custom toolbar associated with the navigation controller. (read-only)

@property(nonatomic,readonly) UIToolbar *toolbar Discussion This property contains a reference to the built-in toolbar managed by the navigation controller. Access to this toolbar is provided solely for clients that want to present an action sheet from the toolbar. You should not modify the UIToolbar object directly.

Management of this toolbar’s contents is done through the custom view controllers associated with this navigation controller. For each view controller on the navigation stack, you can assign a custom set of toolbar items using the setToolbarItems:animated: method of UIViewController.

编辑:所以你应该这样做:

[self setToolbarItems:items animated:NO];

编辑:以下是添加右栏按钮项目的方法:

- (void) addRightButton
{
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[rightBtn setImage:[UIImage imageNamed:@"mybutton.png"] forState:UIControlStateNormal];
rightBtn.frame = CGRectMake(0, 0, 70, 40 );
[rightBtn addTarget:self action:@selector(myButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
self.navigationItem.rightBarButtonItem = rightBarBtn;
}

编辑:要以编程方式创建灵活/固定空间项目,请使用:

- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action

systemItem 的可设置值包括 UIBarButtonSystemItemFlexibleSpace 和 UIBarButtonSystemItemFixedSpace。检查 UIBarButtonItem 类的文档:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html

编辑:问题已澄清。底部的工具栏与 navigationItem 或导航 Controller 无关,它只是一个 UIToolbar。您需要在 IB 中完全设置它,或者在您的类中设置一个 socket 并在代码中设置/完成它。

关于iphone - 设置导航 Controller 的工具栏项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5066924/

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