简体   繁体   中英

Blank/black Screen in ios simulator on startup

I am trying to input user information into coredata so that I can than send it to my php and do a MySQL login. However, when I was testing JUST the coredata part, all I got was a black/blank screen with no xcode error or error reports (after the custom image loading screen, there should me my background and my buttons). Below is my code, obviously excluding storyboard and the xcdatamodeld (to actually store the core data input). Anything I am doing wrong?

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

Reason is , you are not adding any viewcontrollers in your window.

Just add your logincontroller on it,

like

 - (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
      self.window = [[UIWindow alloc]
                initWithFrame:[[UIScreen mainScreen] bounds]];
      [self.window addSubView:viewController.view]; 
      // OR self.window.rootController = viewController;
      [self.window makeKeyAndVisible];
      return YES;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM