在选项卡式iOS应用程序中更改起始视图

时间:2013-10-05 07:30:02

标签: ios view startup appdelegate

我创建了一个标签式应用程序并创建了另一个名为LogInScreen的文件, 我想将应用程序启动时出现的常用视图更改为这个新的LogInFile,但我尝试的所有内容都不起作用。

这是AppDelegate.h文件:

#import <UIKit/UIKit.h>
#import "LogInScreen.h"

@interface LogInScreen : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) LogInScreen *logInView;

@end


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

在第一个@implementation出现一条错误消息:类'LogInScreen'的重复接口定义,我猜是因为LogInScreen.h文件。我不知道怎么让它正常工作。

这是AppDelegate.m的开始:

#import "AppDelegate.h"

@implementation AppDelegate

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

  [self.logInView addSubview:_logInView.view];
  [self.logInView makeKeyAndVisible];
  [self.logInView setRootViewController:_logInView];


// Override point for customization after application launch.
return YES;
}

我在这个网站上找到了这个代码,但它没有用......

这是LogInScreen.h文件:

#import <UIKit/UIKit.h>

@interface LogInScreen : UIViewController{

  NSString *password;

  IBOutlet UITextField *passwordField;

}

- (IBAction)enterPassword;

- (IBAction)savepassword:(id)sender;

- (IBAction)returnKey:(id)sender;

- (IBAction)switchView:(id)sender;


@end

和LogInScreen.m:

#import "LogInScreen.h"
#import "FirstViewController.h"
/* #import "AppDelegate.h"

int main(int argc, char * argv[])
{
   @autoreleasepool {
    return UIApplicationMain()(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
 */

@interface LogInScreen ()

@end

@implementation LogInScreen

- (IBAction)enterPassword
{
NSString *passwordString = [NSString stringWithFormat:@"12345"];

if ([passwordField.text isEqualToString:passwordString]) {
    /*[self switchView:nil]; */
}

else {
    UIAlertView *incorrectPassword = [[UIAlertView alloc] initWithTitle:@"Falsches   Passwort" message:@"Dieses Passwort ist falsch! Geben Sie bitte das korrekte Passwort ein!" delegate:self cancelButtonTitle:@"Zurück" otherButtonTitles:nil, nil];
    [incorrectPassword show];
}
}

- (IBAction)savepassword:(id)sender {
password = [[NSString alloc] initWithFormat:passwordField.text];
[passwordField setText:password];
NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
[stringDefault setObject:password forKey:@"stringKey"];
}

- (IBAction)returnKey:(id)sender {
[sender resignFirstResponder];
}

- (IBAction)switchView:(id)sender {
FirstViewController *main = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:main animated:YES completion:NULL];
 }



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[passwordField setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey"]];

[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

如果有人可以帮助我会很酷

2 个答案:

答案 0 :(得分:0)

根据我的评论,您可以使用此代码在主标签视图之前显示模式登录视图:

// Main menu view controller    
MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:mainNavigationController, nil];
self.window.rootViewController = self.tabBarController;
[self.window.rootViewController.view setOpaque:NO];
self.window.rootViewController.view.backgroundColor = [UIColor clearColor];
self.tabBarController.selectedIndex = 0;
[self.window setRootViewController:self.tabBarController];

[self.window makeKeyAndVisible];

// Login modal view controller
LoginViewController *loginController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
[self.tabBarController presentViewController:loginController animated:NO completion:nil];

答案 1 :(得分:0)

将您的登录屏幕作为主要视图放在MainStoryBoard中。拖放一个uitabbarcontroller将一个segue从登录屏幕连接到uitabbar,并从登录屏幕的按钮显示该标签栏的模态。