gpt4 book ai didi

iphone - 更改 Root View Controller 后,UI 导航在我的 iPhone 应用程序中不起作用

转载 作者:行者123 更新时间:2023-11-29 03:51:43 24 4
gpt4 key购买 nike

我正在为 iPhone 开发 ios 应用程序。我遇到登录屏幕问题..我开发了没有登录屏幕的应用程序。但现在我想首先提供登录选项,登录后我想显示我的应用程序的实际屏幕。

所以我对代码所做的如下......

首先,在没有登录屏幕的情况下,我在 appdeleget.m 中调用的函数如下..

-(bool)DeafultSideBar{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
ViewController *homeViewController = [[ViewController alloc]init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar.png"] forBarMetrics:UIBarMetricsDefault];

SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:navController];
_viewController = rootController;

LeftSlideViewController *leftController = [[LeftSlideViewController alloc] init];
rootController.leftViewController = leftController;
// [FBLoginView class];

self.window.rootViewController = rootController;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;


}

这是我从 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions AppDelegete.m 文件的方法调用的函数

现在我想显示登录屏幕,所以我制作了一个登录 View Controller ,然后我修改了我的 -

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

用这个方法..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LogInViewController *logInViewController = [[LogInViewController alloc]init];


self.window.rootViewController = logInViewController;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;




}

我的登录屏幕上有一个按钮,单击该按钮会执行与我之前在应用程序中没有登录屏幕时所做的相同的操作,如下所示。

- (IBAction)SignInCalled:(id)sender {
AppDelegate *appdelegete=[[AppDelegate alloc]init];

appdelegete.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

ViewController *homeViewController = [[ViewController alloc]init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar.png"] forBarMetrics:UIBarMetricsDefault];

SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:navController];
_viewController = rootController;

LeftSlideViewController *leftController = [[LeftSlideViewController alloc] init];
rootController.leftViewController = leftController;



[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
//[self presentModalViewController:rootController animated:YES];
appdelegete.window.rootViewController = rootController;

appdelegete.window.backgroundColor = [UIColor whiteColor];
[appdelegete.window makeKeyAndVisible];
[UIView commitAnimations];



// [FBLoginView class];




}

现在的问题是,一切正常,但在加载应用程序 View 时单击该按钮后,没有一个导航过程起作用。我无法使用以下代码导航到任何其他屏幕..

 ViewController *HomeView=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:HomeView animated:YES];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:HomeView];

[menuController setRootController:navController animated:YES];

我知道我在代码中的某个地方犯了一些愚蠢的错误,所以有人可以指导我如何解决这个问题..

最佳答案

您的 Controller 层次结构看起来非常复杂,无法弄清楚您想要实现的目标。以下是我首先进行的更新后的代码更改。

首先是应用程序委托(delegate)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LogInViewController *logInViewController = [[LogInViewController alloc]init];

self.window.rootViewController = logInViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

然后按钮ibaction

- (IBAction)SignInCalled:(id)sender 
{
ViewController *homeViewController = [[ViewController alloc]init];

SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:homeViewController];

LeftSlideViewController *leftController = [[LeftSlideViewController alloc] init];
rootController.leftViewController = leftController;

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootController];

self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:navController animated:YES completion:NULL];

// [FBLoginView class];
}

关于iphone - 更改 Root View Controller 后,UI 导航在我的 iPhone 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16996566/

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