UINavigationBar 中的活动指示器

发布于 2024-12-04 19:17:54 字数 520 浏览 1 评论 0原文

我已经阅读了有关此特定主题的一些答案,但由于某种原因,我的代码似乎不起作用。它位于 UISearchBarDelegate 委托方法 -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 中,

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem *activity = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[[self navigationItem] setRightBarButtonItem:activity];
[activity release];
[activityIndicator startAnimating];

非常感谢任何帮助或建议!

I've read a few answers about this particular topic, but for some reason, my code doesn't seem to work. It's within the UISearchBarDelegate delegate method -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem *activity = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[[self navigationItem] setRightBarButtonItem:activity];
[activity release];
[activityIndicator startAnimating];

Any help or suggestions are much appreciated!

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

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

发布评论

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

评论(3

巴黎盛开的樱花 2024-12-11 19:17:54

我相信 UIActivityIndi​​catorView 的指定初始化程序是 initWithActivityIndi​​catorStyle:。尝试像这样创建activityIndi​​cator

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

I believe the designated initializer for UIActivityIndicatorView is initWithActivityIndicatorStyle:. Try creating activityIndicator like this.

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
傲世九天 2024-12-11 19:17:54

试试这个

UIView *view_actviti = [[UIView alloc] initWithFrame:CGRectMake(6,310,59,32)];
    UIActivityIndicatorView *act =[[UIActivityIndicatorView alloc] init];
    act.frame=CGRectMake(0, 0, 30, 30);
    UIBarButtonItem *actItem = [[[UIBarButtonItem alloc] initWithCustomView:view_actviti] autorelease];
    [view_actviti addSubview:act];
    self.navigationItem.rightBarButtonItem = actItem;
    [act startAnimating];

try this

UIView *view_actviti = [[UIView alloc] initWithFrame:CGRectMake(6,310,59,32)];
    UIActivityIndicatorView *act =[[UIActivityIndicatorView alloc] init];
    act.frame=CGRectMake(0, 0, 30, 30);
    UIBarButtonItem *actItem = [[[UIBarButtonItem alloc] initWithCustomView:view_actviti] autorelease];
    [view_actviti addSubview:act];
    self.navigationItem.rightBarButtonItem = actItem;
    [act startAnimating];
姐不稀罕 2024-12-11 19:17:54

试试这个:

UIActivityIndicatorView *activityIndicator = 
    [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem * barButton = 
    [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];

[[self navigationItem] setRightBarButtonItem:barButton];

[barButton release];
[activityIndicator startAnimating];

也可以使用它来停止和删除 ActivityIndi​​cator:

[[self navigationItem] setLRightBarButtonItem:nil];
[activityIndicator stopAnimating];
[activityIndicator release];

try this:

UIActivityIndicatorView *activityIndicator = 
    [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem * barButton = 
    [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];

[[self navigationItem] setRightBarButtonItem:barButton];

[barButton release];
[activityIndicator startAnimating];

Also use this for stopping and removing activityIndicator:

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