ios - 导航 Controller 工具栏中的 UIBarButton

标签 ios objective-c xcode

我正在用头撞墙,认为这应该很简单,但我想不通。

我有一个应用程序,其中包含同一个 Navigataion Controller 类的多个实例。是否可以将代码添加到所述导航 Controller 类(在本例中为工具栏的 UIBarButtonItems),以便我在该类中所做的任何事情都会显示在该导航 Controller 中的任何位置?

我添加了以下代码,但工具栏上没有显示任何内容:

UIBarButtonItem *flexibleSpace =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemSystemItemAdd target:self action:nil];

UIBarButtonItem *flexibleSpace =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

NSArray *toolbarItems = [NSArray arrayWithObjects:flexibleSpace, add, flexibleSpace];

[toolBar setItems:toolbarItems animated:NO];

最佳答案

在调用 -arrayWithObjects: 时,您忘记了用 nil 终止列表。

NSArray *toolbarItems = [NSArray arrayWithObjects:flexibleSpace, add, flexibleSpace, nil];

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/#//apple_ref/occ/clm/NSArray/arrayWithObjects :

关于ios - 导航 Controller 工具栏中的 UIBarButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29781427/

相关文章:

objective-c - 异常解析 NSDictionary 内的 NSDictionary

ios - 在非官方库中禁用 ARC 会导致 Apple 出现问题?

ios - Xcode:进程启动失败 - 安全

ios - 未从邮件应用程序调用 openURL

ios - 类型 'GameScene' 的值在 Swift 中没有成员 'presentViewController'

iphone - 在 scrollView 内的 ImageView 中裁剪缩放图像

ios - 如何为多个目标提供(faSTLane)下载元数据?

ios - IOS7和 "Terminated due to Memory Pressure"中的内存管理

ios - barbuttonitem 现在显示,presentmodalviewcontroller

iOS - 如何将事件添加到 Objective C 中的 kal 库?