我正在尝试将用户信息输入到 coredata 中,以便可以将其发送到我的 php 并进行 MySQL 登录。但是,当我只测试 coredata 部分时,我得到的只是一个黑色/空白屏幕,没有 xcode 错误或错误报告(在自定义图像加载屏幕之后,应该有我的背景和按钮)。下面是我的代码,显然不包括情节提要和 xcdatamodeld(实际存储核心数据输入)。有什么我做错了吗?
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;
}
登录视图控制器.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
登录视图控制器.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
联系人.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Contacts : NSManagedObject
@property (nonatomic, retain) NSString * username;
@property (nonatomic, retain) NSString * password;
@end
联系人.m
#import "Contacts.h"
@implementation Contacts
@dynamic username;
@dynamic password;
@end