gpt4 book ai didi

iOS 导航问题 : after pushing a ViewController, 导致导航栏显示上一个 ViewController 的导航项

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:10 25 4
gpt4 key购买 nike

这种情况很少发生,我不知道如何重现,但有时确实会发生,我想修复它。

ViewController A 中,如果我将 ViewController B 插入,有时(并非总是)当 ViewController B 确实出现时,导航栏是显示 ViewController A 的导航栏项目,而不是 ViewController B 的导航栏项目。如果我单击后退按钮,我将无法返回到 ViewController A,卡在 ViewController B 中。

ViewController A的导航项中添加了一个UIBarButtonItemViewController A的导航项会响应一些更新事件。这是导致这个问题的原因吗?

推送ViewController B的代码

ViewControllerB* viewControllerB = [ViewControllerB new];
[self.navigationController pushViewController:viewControllerB animated:YES];

更新 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];
});
}
}
}

/** * 在导航栏右侧显示更新按钮 */

-(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;

}

}

}

有人知道吗?谢谢。

最佳答案

终于找到这个问题的原因了。就是我尝试隐藏viewWillDisappear中的导航栏。现在 iOS 允许我通过从屏幕的左边缘平移来返回到之前的 View 。但是从左边缘平移时,如果我取消这个 Action ,然后平移回到左边缘,导航栏就会进入这种奇怪的状态。

关于iOS 导航问题 : after pushing a ViewController, 导致导航栏显示上一个 ViewController 的导航项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21330676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com