0

我创建了一个选项卡式应用程序并创建了另一个名为 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

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

4

2 回答 2

0

将您的登录屏幕作为初始视图放置在 MainStoryBoard 中。拖放一个 uitabbarcontroller 将一个 segue 从 loginscreen 连接到 uitabbar 并从登录屏幕中的按钮显示该选项卡栏的模式。

于 2013-10-05T08:30:39.007 回答
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];
于 2013-10-05T07:42:51.350 回答