這種情況很少發生,我不知道如何重現它,但它有時會發生,我會喜歡解決它。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