【发布时间】:2012-05-01 14:30:24
【问题描述】:
我想在我的应用程序中添加一个加载活动指示器,类似于邮件应用程序中的加载活动指示器,右侧有状态文本。我正在使用 UINavigationController,所以我知道我需要在希望显示它的每个视图上设置 toolbarItems 数组。我可以添加活动指示器,它确实会显示出来,但是当我尝试使用下面的代码添加文本字段时,文本不会显示。有没有办法以编程方式创建一个容器,该容器同时具有状态文本和 UIActivityIndicatorView,如果添加到 toolbarItems 数组中,该容器将显示出来。
UIBarButtonItem *textFieldItem = [[[UIBarButtonItem alloc] initWithCustomView:textField] autorelease];
self.toolbarItems = [NSArray arrayWithObject:textFieldItem];
更新:
我根据 pdriegen 的代码创建了一个从 UIView 派生的类。
我还在我的控制器中将此代码添加到 viewDidLoad
UIProgressViewWithLabel * pv = [[UIProgressViewWithLabel alloc] init];
UIBarButtonItem * pvItem = [[UIBarButtonItem alloc] initWithCustomView:pv];
[self setToolbarItems:[NSMutableArray arrayWithObject:pvItem]];
目前工具栏中没有显示任何内容。我错过了什么?
【问题讨论】:
-
你试过使用 UILabel 吗?
-
可能是间距问题...添加一个灵活的空间项
-
感谢您的建议。仍然只显示活动指示器。你觉得我的例子有什么问题吗?
标签: ios xcode uinavigationcontroller uibarbuttonitem uiactivityindicatorview