我创建了一个选项卡式应用程序并创建了另一个名为 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
如果有人可以帮助我会很酷