我越来越看到在代码中创建所有视图的好处,并希望完全切换到这种开发风格。正如标题所示,我遇到了一些小问题。像往常一样,我确信这是我几乎没有忽略的东西。看看我的代码,你能提供一个建议吗?ARC 已启用。
发生的情况是,-(id)init;
当我在应用程序委托中检查该方法时该方法返回 nil,我似乎无法弄清楚为什么......该self = [super init];
调用似乎总是有效,但在这种情况下不是。
主.m:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([BCAppDelegate class]));
}
}
在BCAppDelegate.m中:
@implementation BCAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
BCViewController *bcv = [[BCViewController alloc] init];
if (bcv == nil) { printf("it's nil\n"); }
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[view setBackgroundColor:[UIColor blueColor]];
[bcv setView:view];
[self.window setRootViewController:bcv];
[self.window makeKeyAndVisible];
return YES;
}
BCViewController.h:
@interface BCViewController : UIViewController <UIImagePickerControllerDelegate>
{
/*some IVARS*/
}
-(id)init;
@end
在BCViewController.m中:
@implementation BCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { return nil; }
-(id)init
{
self = [super init];
if (!self) {
return nil;
}
return self;
}
- (void)loadView
{
/* No Code yet */
}