0

我在导航栏中添加了图像,需要添加右栏刷新按钮。但是添加后右栏按钮无法在导航中显示。为什么?

这里的代码在导航栏添加图像:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"topbar.png"] forBarMetrics:UIBarMetricsDefault];

这里添加右栏按钮viewDidLoad

UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh: )];

NSArray *actionButtonItems = @[refreshItem];
self.navigationController.navigationItem.rightBarButtonItems = actionButtonItems;
4

4 回答 4

2

您不应该添加到 self.navigationcontroller。

做这样的事情会解决你的问题。

  self.navigationItem.rightBarButtonItem  = refreshItem; 
于 2013-12-18T10:02:12.700 回答
0

替换这个

self.navigationController.navigationItem.rightBarButtonItems = actionButtonItems;

和:

self.navigationItem.rightBarButtonItems = actionButtonItems;
于 2013-12-18T09:56:09.537 回答
0

尝试使用以下代码

UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh: )];      
self.navigationItem.rightBarButtonItem = refreshItem;
于 2013-12-18T09:54:13.217 回答
0
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Refresh"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(rightButtoneClicked:)];
self.navigationItem.rightBarButtonItem = rightButton;

在 viewDidLoad 中右键此代码,您将在右侧获得刷新按钮。

于 2013-12-18T09:54:26.223 回答