1
我正在尝试向coredata输入用户信息,以便我可以将它发送到我的php并执行MySQL登录。然而,当我测试只是coredata部分时,我所得到的只是一个黑屏/空白屏幕,没有xcode错误或错误报告(在自定义图像加载屏幕后,应该有我的背景和我的按钮)。下面是我的代码,显然排除故事板和xcdatamodeld(实际存储核心数据输入)。我做错了什么?启动时在ios模拟器中显示空白/黑屏
Appdelegate.h
#import <UIKit/UIKit.h>
@class LoginViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
LoginViewController *viewController;
}
@property (strong, nonatomic) IBOutlet LoginViewController *viewController;
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
@end
Appdelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
@synthesize viewController;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
return YES;
}
LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController {
UITextField *username;
UITextField *password;
}
@property (strong, nonatomic) IBOutlet UITextField *username;
@property (strong, nonatomic) IBOutlet UITextField *password;
- (IBAction)saveData:(id)sender;
@end
LoginViewController.m
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "Contacts.h"
@interface LoginViewController()
@end
@implementation LoginViewController
@synthesize username, password;
- (IBAction)saveData:(id)sender {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context];
[newContact setValue:username.text forKey:@"username"];
[newContact setValue:password.text forKey:@"password"];
username.text = @"";
password.text = @"";
NSError *error;
[context save:&error];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
@end
Contacts.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Contacts : NSManagedObject
@property (nonatomic, retain) NSString * username;
@property (nonatomic, retain) NSString * password;
@end
Contacts.m
#import "Contacts.h"
@implementation Contacts
@dynamic username;
@dynamic password;
@end
我欣赏的帮助,但它不喜欢.window。它一直说没有找到该物业。我应该怎么做才能“找到”它 – user1746156
我在编辑plist版本和归档构建后意外地点击了删除键。保持黑色的窗户,花费2小时试图找到它。 git diff向我展示了这个问题。哈哈谢谢。 +1 <3 – Kalle