这种情况很少发生,我不知道如何重现它,但它有时会发生,我会喜欢解决它。iOS导航问题:在推送ViewController后,导致显示前一个ViewController的导航条的导航栏
在ViewController A
,如果我在,有时候(不总是)在ViewController B
没有出现,导航栏显示的ViewController A
导航栏项目,而不是那些ViewController B
推ViewController B
。如果我点击后退按钮,我不能回到ViewController A
,陷入ViewController B
。
A UIBarButtonItem
已添加到导航条目ViewController A
,导航条目ViewController A
将根据某些事件进行更新。这是导致这个问题的原因吗?
代码为ViewController A
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if(NumberOfCalendarOperations == 0){
[self showNavigatorBarButtons];
}
else{
[self startRefreshAnimationOnUpdateButton];
}
}
//This method is triggered through notification when the number of operations in calendarOperationQueue is changed
-(void)calendarOperationQueueStateDidChange:(NSNotification*)notification{
if(NumberOfCalendarOperations == 0){
if (self.isShowActivityIndicator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showNavigatorBarButtons];
});
}
}
else{
if (!self.isShowActivityIndicator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self startRefreshAnimationOnUpdateButton];
});
}
}
}
/** 推ViewController B
ViewControllerB* viewControllerB = [ViewControllerB new];
[self.navigationController pushViewController:viewControllerB animated:YES];
代码用于更新导航项*显示在导航栏 右侧的更新按钮*/
-(void)showNavigatorBarButtons{
self.isShowActivityIndicator = NO;
UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sync.png"] style:UIBarButtonItemStylePlain target:self action:@selector(updateButtonDidPress:)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:updateButton, nil]];}
/** * 上开始更新按钮 */
-(void)startRefreshAnimationOnUpdateButton{
if (self.navigationController.topViewController != self) {
return;
}
self.isShowActivityIndicator = YES;
UIView* updateButtonView = nil;
for (UIView *subViewInNavigationBar in self.navigationController.navigationBar.subviews){
NSString *subViewClassAsString = NSStringFromClass([subViewInNavigationBar class]);
if ([subViewClassAsString compare:@"UINavigationButton" /* TODO: be careful with this */
options:NSCaseInsensitiveSearch] == NSOrderedSame){
if ([subViewInNavigationBar isKindOfClass:[UIView class]] == YES){
if(updateButtonView == nil){
updateButtonView = subViewInNavigationBar;
}
else if(subViewInNavigationBar.center.x < updateButtonView.center.x){
updateButtonView = subViewInNavigationBar;
}
}
}
}
for (UIView *subViewsInButton in updateButtonView.subviews){
if ([subViewsInButton isKindOfClass:[UIImageView class]] == YES &&
subViewsInButton.frame.origin.x != 0.0f &&
subViewsInButton.frame.origin.y != 0.0f){
[subViewsInButton removeFromSuperview];
CGRect activityIndicatorFrame = self.updateButtonActivityIndicator.frame;
activityIndicatorFrame.origin.x = (CGRectGetWidth(updateButtonView.frame)/2.0f) - (CGRectGetWidth(activityIndicatorFrame)/2.0f);
activityIndicatorFrame.origin.y = (CGRectGetHeight(updateButtonView.frame)/2.0f) - (CGRectGetHeight(activityIndicatorFrame)/2.0f);
self.updateButtonActivityIndicator.frame = activityIndicatorFrame;
[self.updateButtonActivityIndicator startAnimating];
[updateButtonView addSubview:self.updateButtonActivityIndicator];
return;
}
}
}
任何人都得到了一个线索刷新动画?谢谢。
你是怎么在ViewControllerA中添加栏按钮的? – channi
任何代码显示? –
是的,一个UIBarButtonItem被添加到A的导航项中,并且A的导航项将被更新以响应一些事件。 – Jibeex