2013-10-05 11 views
0

我已創建了選項卡式應用程序並創建了另一個文件,稱爲LogInScreen, 我想更改應用程序啓動時出現的常見視圖,以此新LogInFile,但我嘗試過的所有內容沒有工作。更改選項卡式iOS應用程序中的起始視圖

這是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 

將是冷靜,如果有人可以幫助我

+0

IDE被稱爲Xcode,而不是xCode,但無論如何,它與此問題無關。 – 2013-10-05 07:30:50

+0

改變了它..... –

+0

你想在訪問標籤主視圖之前有一個登錄屏幕? – RFG

回答

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]; 
+0

這對我不起作用,或者我把這段代碼放在錯誤的文件中......但是我嘗試了一些,但它不工作...... :( –

+0

把它放在 - (BOOL)應用程序中:(UIApplication * )應用didFinishLaunchingWithOptions:(NSDictionary *)launchOptions。 – RFG

0

將您的登錄屏幕在INTIAL視圖MainStoryBoard。拖放一個uitabbarcontroller將一個segue從登錄屏幕連接到uitabbar,並在登錄屏幕中顯示一個按鈕的tabbar模式。

相關問題