ios - 将刷新按钮添加到导航栏

标签 ios iphone objective-c uitableview

大家好,如果您可以查看下面的代码然后提供一些帮助,我很难尝试让这个导航栏包含一个刷新按钮,这是我的原始代码以及我找到的 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/

相关文章:

iOS:AutoresizingMask 未调整大小以适应屏幕上的 map 或 View

iphone - 在 iPhone/iPad 上查看网站上的 div 之间的空间/间隙

objective-c - 应用沙盒相关

ios - 退出应用程序时无法使用 NSUserDefaults 保存整数

objective-c - 在 OSX 中创建许可协议(protocol)屏幕

ios - 更改 Phonegap 用户代理

android - 如何跨移动应用共享文本和翻译?

iphone - 开发者可以在邮件应用程序中访问未读邮件吗?

iphone - 你如何使 UIView 的幻灯片从左到右并在 iPhone 中相互对接?

iphone - 静音内置 iPhone 麦克风