我有一个登录视图,它指向一个UITabBarController
带有四个选项卡的选项卡。我想要的是当密码为空或错误时,提示用户留在同一视图(登录视图)而不是标签栏控制器。换句话说,如果密码正常(非空且正确),我希望能够查看标签栏。是否可以一直显示登录视图,直到提供的密码正确?有任何想法吗?
问问题
236 次
3 回答
0
您所描述的是模态视图控制器。如果您有一个现有的登录控制器,请展示它:
[someViewController presentViewController:loginController animated:YES completion:nil]
这将定位loginController
在所有其他控制器之上。当用户输入了正确的密码(并且只有这样!)你应该关闭它:
[self dismissViewControllerAnimated:YES completion:nil];
如果您希望loginController
有一个标题栏,请记住将其包装在 a 中UINavigationController
并显示导航控制器。
于 2013-04-25T13:13:30.650 回答
0
YourAppDelegate.m:
@interface YourAppDelegate()
@property( nonatomic, retain ) UITabBarController *tabBarController;
@property( nonatomic, retain ) UIViewController *loginViewController;
- (void)allocateAndShowLoginViewController;
- (void)allocateAndShowMenuController;
@end
@implementation YourAppDelegate
@synthesize tabBarController;
@synthesize loginViewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
[self allocateAndShowLoginViewController];
return YES;
}
- (void)allocateAndShowLoginViewController{
// Show Login View Controller (for example:)
// My Sample login view controller uses delegate to report when user has been logged in
self.loginViewController = [[[UIViewController alloc] initWithDelegate:self] autorelease];
self.window.rootViewController = loginViewController;
}
- (void)allocateAndShowTabBarController{
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
UINavigationController *viewController1 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];
UINavigationController *viewController2 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.tabBarController.customizableViewControllers = nil;
self.window.rootViewController = self.tabBarController;
}
#pragma mark - loginViewControllerDelegate
- (void)loginViewControllerDidLogin:(PSLoginViewController*)controller{
[self allocateAndShowMenuController];
}
类似的东西
于 2013-04-25T13:14:11.940 回答
0
据我了解,您想在某个时间禁用标签栏。
如果你使用UITabBarController
你可以使用
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
return NO;
}
或者你可以禁用userInteractionEnabled
myTabBar.userInteractionEnabled = NO;
您还可以向您UITabBarController
的示例添加一些子视图以淡出您的标签栏
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.backgroundColor = [UIColor blackColor];
view.alpha = 0.3f;
[self.tabBarController.view addSubview:view];
[view release];
于 2013-04-25T13:11:50.757 回答