我已经阅读了关于这个特定主题的一些答案,但由于某种原因,我的代码似乎不起作用。它位于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];
非常感谢任何帮助或建议!
答案 0 :(得分:2)
我认为UIActivityIndicatorView
的指定初始值设定项为initWithActivityIndicatorStyle:
。尝试像这样创建activityIndicator
。
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
答案 1 :(得分:1)
试试这个
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];
答案 2 :(得分:0)
试试这个:
UIActivityIndicatorView *activityIndicator =
[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem * barButton =
[[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[[self navigationItem] setRightBarButtonItem:barButton];
[barButton release];
[activityIndicator startAnimating];
还可以使用它来停止和删除activityIndicator:
[[self navigationItem] setLRightBarButtonItem:nil];
[activityIndicator stopAnimating];
[activityIndicator release];