1

I found strange behavior in iOS 6, didn't test for other versions. I created a simple navigation based application with to views. when i click on a button on the first view, the second view is pushed. When then i click back button i return to the first view. Both views are nested from DetailViewConotrller.

@implementation DetailViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *searchCancelButton = [[UIBarButtonItem alloc] initWithTitle:@"custom1" style:UIBarButtonItemStyleBordered target:self action:nil];
    [searchCancelButton setBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
    UIBarButtonItem *searchCancelButton1 = [[UIBarButtonItem alloc] initWithTitle:@"custom2" style:UIBarButtonItemStyleBordered target:self action:nil];
    [searchCancelButton1 setBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
    [self.navigationItem setRightBarButtonItems: [[NSArray alloc] initWithObjects:searchCancelButton, searchCancelButton1, nil] animated:NO];
}


@end

I call method [self.navigationItem setRightButtonItems: animated:] with animated parameter NO, but buttons are still animating. The interesting thing is, when this method is called with only one UIBarButtonItem it works correct and no annimation appears.

Are any thoughts why this method behaves such way? Is this a bug or do I something wrong? Or are any suggestions how to avoid animation for navigation items.

4

1 回答 1

0

只需将您的代码更改为:

- (void)viewDidLoad
{
 [super viewDidLoad];

  UIBarButtonItem *searchCancelButton = [[UIBarButtonItem alloc] initWithTitle:@"custom1" style:UIBarButtonItemStyleBordered target:self action:nil];
  [searchCancelButton setBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
  UIBarButtonItem *searchCancelButton1 = [[UIBarButtonItem alloc] initWithTitle:@"custom2" style:UIBarButtonItemStyleBordered target:self action:nil];
  [searchCancelButton1 setBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
  [self.navigationItem setRightBarButtonItems: [[NSArray alloc] initWithObjects:searchCancelButton, searchCancelButton1, nil] animated:NO];

}

在您当前的实现中,您设置了两次导航按钮。首先使用属性,然后调用方法。可能将 rightBarButtonItems 设置为带有动画的 setRightBarButtonItems。

于 2013-07-25T10:06:13.733 回答