Can';t弹出iOS视图控制器。不确定,但我认为';导航控制器有什么问题吗
我在弹出视图时遇到问题 应用程序代理Can';t弹出iOS视图控制器。不确定,但我认为';导航控制器有什么问题吗,ios,objective-c,uiviewcontroller,uinavigationcontroller,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,我在弹出视图时遇到问题 应用程序代理 @implementation MAAppDelegate @synthesize navController; @synthesize detailViewController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow
@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];
所以我不明白为什么我这样做时,按钮上的选择器(我知道会触发,因为我在日志中找到了正确的位置):
它不会返回到初始视图控制器。您似乎混淆了popToViewController和popViewControllerAnimated。popViewControllerAnimated从堆栈中删除当前视图,并将新堆栈置于活动视图控制器的顶部。popToViewController弹出堆栈,直到列出的视图控制器位于堆栈顶部 由于您使用self调用popToViewController,它将查看并看到请求的视图控制器已经位于堆栈顶部,并且什么也不做。如果您希望返回一个视图控制器,那么您的呼叫应该是
[self.navigationController popViewControllerAnimated:YES];
我使用下面的代码弹出iOS 8中以前的viewcontroller
[自我呈现ModalviewController:viewcontroller动画:是] 嗯,你不应该。您可以通过弹出视图控制器来弹出它们,在这里您将在顶部显示另一个视图控制器。
[self.navigationController popViewControllerAnimated:YES];