gpt4 book ai didi

ios - 无法弹出 iOS viewController。不确定,但我认为这与导航 Controller 有关

转载 作者:行者123 更新时间:2023-11-29 03:07:23 39 4
gpt4 key购买 nike

我在尝试弹出 View 时遇到问题

应用委托(delegate)

@implementation MAAppDelegate
@synthesize navController;
@synthesize detailViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Init the navController for the Master Detail View of the grade cells

UINavigationController *navController = [[UINavigationController alloc] init];


detailViewController = [[UIViewController alloc] init]; //step6
navController = [[UINavigationController alloc] initWithRootViewController:[[MAController alloc] init]]; //step7


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navController; //step8
[self.window makeKeyAndVisible];


// Set MAController as rootViewController
//self.window.rootViewController = [[MAController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];




// Use the insanely cool TSMessages to show network alerts
[TSMessage setDefaultViewController: self.window.rootViewController];
return YES;
}

viewController的第一部分

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.


[self.navigationController setNavigationBarHidden:YES];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:self action:@selector(home:)];
self.navigationItem.leftBarButtonItem=newBackButton;

稍后,当我更改 viewController 时

    NSLog(@"Opened progress report");

UIViewController *detailViewControl = [[UIViewController alloc] init];

// Set progress report as the view controller
[self.navigationController pushViewController:detailViewControl animated:YES];

UIImage *background = [UIImage imageNamed:@"bg"];

// Add static image bg
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];

// Add blurred layer to image when tableView goes in front of it
self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];



[self.navigationController setNavigationBarHidden:NO];

所以我不明白为什么当我这样做时,按钮中的选择器(我知道会触发,因为我在日志中得到了 Righthtere):

    -(void)home:(UIBarButtonItem *)sender {
NSLog(@"Righthtere");
// Set progress report as the view controller
[self.navigationController popToViewController:self animated:YES];

}

它不会返回到初始 View Controller 。

最佳答案

您似乎混淆了 popToViewController 和 popViewControllerAnimated。 popViewControllerAnimated 从堆栈中移除当前 View ,并将新堆栈置于事件 View Controller 的顶部。 popToViewController 弹出堆栈,直到列出的 View Controller 位于堆栈顶部。

由于您正在使用 self 调用 popToViewController,它会查看请求的 View Controller 已经在堆栈顶部并且什么都不做。如果你想返回一个 View Controller ,那么你的电话应该是。

[self.navigationController popViewControllerAnimated:YES];

关于ios - 无法弹出 iOS viewController。不确定,但我认为这与导航 Controller 有关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22614787/

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