UIToolbar 项目未显示

发布于 2024-08-03 04:07:29 字数 948 浏览 5 评论 0原文

我有一个 UINavigationController,它被推送到 DetailsViewController。在这个DetailsViewController中,我想使用每个UINavigationController(至少从iPhone OS3.0开始)附带的工具栏。

因此,在 DetailsViewController 的 viewDidLoad 中,我创建了一个 UIBarButtonItem,将其添加到数组中并将其传递给导航控制器:

- (void) viewDidLoad {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];  
    NSArray *items = [NSArray arrayWithObject: item];

    TestUIAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    UINavigationController *navController = delegate.navigationController;

    [navController setToolbarItems: items animated:NO];     
    [navController setToolbarHidden: NO animated: YES]; 
}

但是,由于某种原因,当 UIToolbar 在屏幕上动画显示时,该项目不会添加到工具栏。

是否必须使用 UIToolbar 完成某种特定的顺序才能使其工作?

PS:应用程序处于(强制)横向模式,并且 navigationController.view 具有旋转变换。这可能有什么关系吗?

I have a UINavigationController that gets pushed a DetailsViewController. In this DetailsViewController, I want to use the toolbar that comes with every UINavigationController (atleast, since iPhone OS3.0).

So, in viewDidLoad in my DetailsViewController I create a UIBarButtonItem, I add it to an array and hand it off to the navigation controller:

- (void) viewDidLoad {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];  
    NSArray *items = [NSArray arrayWithObject: item];

    TestUIAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    UINavigationController *navController = delegate.navigationController;

    [navController setToolbarItems: items animated:NO];     
    [navController setToolbarHidden: NO animated: YES]; 
}

But, for some reason, while the UIToolbar is animated on to screen, the item is not added to the toolbar.

Is there some sort of specific order things have to be done with the UIToolbar for this to work?

P.S.: the application is in (forced) landscape mode and the navigationController.view has a rotation transform on it. Could that have anything to do with it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

默嘫て 2024-08-10 04:07:29

做了更多的挖掘和调试,我得出的结论是我尝试修改 navigationController 的方法是错误的。相反,我应该简单地设置DetailsViewController 的toolbarItems 属性。

之后,我的代码运行良好:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];

        NSArray *myToolbarItems = [[NSArray alloc] initWithObjects: item, nil];         
        [self setToolbarItems: myToolbarItems];
        [myToolbarItems release];

    }
    return self;
}

Have done some more digging and debugging and I've come to the conclusion that my approach of trying to modify the navigationController was wrong. Instead I should've simply set the toolbarItems property of the DetailsViewController.

After that, my code worked fine:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];

        NSArray *myToolbarItems = [[NSArray alloc] initWithObjects: item, nil];         
        [self setToolbarItems: myToolbarItems];
        [myToolbarItems release];

    }
    return self;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文