gpt4 book ai didi

ios - 启动时 ios 模拟器中的空白/黑屏

转载 作者:行者123 更新时间:2023-11-29 13:26:36 26 4
gpt4 key购买 nike

我正在尝试将用户信息输入到 coredata 中,这样我就可以将其发送到我的 php 并进行 MySQL 登录。然而,当我只测试核心数据部分时,我得到的只是一个黑色/空白屏幕,没有 xcode 错误或错误报告(在自定义图像加载屏幕之后,应该有我的背景和我的按钮)。下面是我的代码,显然不包括 Storyboard和 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

登录 View Controller .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

最佳答案

原因是,您没有在窗口中添加任何 View Controller 。

只要在上面添加你的logincontroller,

喜欢

 - (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;

关于ios - 启动时 ios 模拟器中的空白/黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12979570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com