[英]Add Refresh Button to Navigation Bar
Hi everyone Im having a pain in the ass time trying to get this Navigation bar to include a Refresh Button if you can look at the code below and then provide some help this is my original code along with the UIBarbutton snippet that i found for the refresh button from another users project on google. 大家好,林先生在尝试获取此导航栏以包含“刷新按钮”时费时费力,如果您可以查看下面的代码,然后提供一些帮助,这是我的原始代码以及为刷新而找到的UIBarbutton代码段Google上另一个用户项目的按钮。 Which i am running into the following errors:
我正在遇到以下错误:
- (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;
}
Write your method as this because you are passing UIBarButton object in call. 将此方法写为此,因为您在调用中传递UIBarButton对象。
- (void) refresh:(id)sender
{
}
OR 要么
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)];
May be this code will help you... 可能这段代码会帮助您...
UIImage *reloadImage = [UIImage imageNamed:@"reload.png"];
UIButton *btnReload = [UIButton buttonWithType:UIButtonTypeCustom];
btnReload.bounds = CGRectMake( 10, 0, reloadImage.size.width, reloadImage.size.height );
[btnReload addTarget:self action:@selector(reloadData:) forControlEvents:UIControlEventTouchUpInside];
[btnReload setImage:reloadImage forState:UIControlStateNormal];
UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc] initWithCustomView:btnReload];
self.navigationItem.leftBarButtonItem = reloadButton;
- (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;
// [button release]; remove this line if you're using ARC
}
It seems that you are already use ARC. 看来您已经在使用ARC。 So you should remove
[button release]
. 因此,您应该删除
[button release]
。 Your book is on the way to the history. 你的书正在走向历史。
Your action selector and the actual method are not the same. 您的动作选择器和实际方法不同。 One is
refresh:
and the other is refresh
. 一种是
refresh:
另一种是refresh
。
Change the selector to match the actual method. 更改选择器以匹配实际方法。
@selector(refresh)
for swift 4 快速4
let refreshButton = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh))
self.navigationItem.rightBarButtonItem = refreshButton
@objc func refresh() {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.