大家好,如果您可以查看下面的代码然后提供一些帮助,我很难尝试让这个导航栏包含一个刷新按钮,这是我的原始代码以及我找到的 UIBarbutton 片段来自谷歌上另一个用户项目的刷新按钮。我遇到了以下错误:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setBackgroundView:nil];
self.tableView.backgroundColor = [ColorHelper charcoalBackgroundImage];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
self.navigationItem.leftBarButtonItem = refresh;
// [button release]; remove this line if you're using ARC
}
- (void) refresh
{
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
最佳答案
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setBackgroundView:nil];
self.tableView.backgroundColor = [ColorHelper charcoalBackgroundImage];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
self.navigationItem.rightBarButtonItem = button;
}
这样写你的方法是因为你在调用中传递了 UIBarButton 对象。
- (void) refresh:(id)sender
{
}
或
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)];
关于ios - 将刷新按钮添加到导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20414417/