问题描述
我还是 IOS 开发的新手,我想通过 MoralViewcontroller 创建一个登录页面.
I am still newbie for IOS Developing, i want to create a login page by MoralViewcontroller.
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
UITabBarController *tabBarController; }
@property (nonatomic,retain) IBOutlet UITabBarController * tabBarController
AppDelegate.m
(void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after app launch
[window addSubview:tabBarController. view];
[window makeKeyAndVisible];
LoginViewController *loginView=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[tabBarController.view presentModelViewcontroller: loginView animated:YES];
}
然而,登录视图无法显示,我认为我为tabBarController定义错误,但我不知道它有什么问题.任何人都可以请给我建议吗?我在做 IOS 5.
However, the login view cannot be shown, I think I define wrongly for tabBarController, but I don't know what wrong with it. Can anyone please advise me? I am doing IOS 5.
非常感谢..
推荐答案
我会从 tabBarController 的 rootView 展示一个 loginView 控制器.
I'd present a loginView controller from the rootView of the tabBarController.
-(void)viewDidLoad
{
//You can also do this inside a conditional statement, if needed
LoginViewController *loginView=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[self.view presentModelViewcontroller:loginView animated:YES];
}
这是第二种方式
AppDelegate.h
AppDelegate.h
@interface AppDelegate : UIResponder {
LoginViewController *loginView;
}
@property (nonatomic,retain) LoginViewController *loginView;
AppDelegate.m
AppDelegate.m
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after app launch
self.loginView=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[window addSubview:loginView. view];
[window makeKeyAndVisible];
}
登录视图控制器.m
成功登录时调用此方法.
Call this method on successful login.
-(IBAction)login:(id)sender
{
//init tabbar with subviews;
UITabBarController *tabBarController = [[UITabBarController alloc] initW....];
[self.view addSubview:tabBarController.view];
}
我更喜欢第一种方法,因为这样您将在 AppDelegate 中保留 tabBarController.
I prefer first method, because in that you will be retaining the tabBarController in AppDelegate.
这篇关于选项卡控制器视图之前的 IOS 登录屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!