ユーザー情報を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;
}
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
連絡先.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