我创造了一个怪物,它让我感到困惑。
我创建了一个 rootViewController 来处理 iOS 应用程序视图和数据。这个控制器有一个 xib,它有助于它的外观。然后,我对自定义 UIView 类进行了子类化,并使用 xib 创建了它的视图。然后我尝试添加 UIView 类及其 xib 以显示在 RootViewControllers 视图中。所以 rootViewController 正在加载它的 NIb,我试图添加这个 UIView 子类并以编程方式安装它的视图。
我的文件层次结构如下..
mockAppDelegate.h
mockAppDelegate.m
mockViewController.h
mockViewController.m
mockViewController.xib
colorPickerLoad.h
colorPickerLoad.m
colorPickerLoad.xib
Code inside h controller file.
#import <UIKit/UIKit.h>
#import "colorPickerLoad.h"
@interface mockViewController : UIViewController
{
}
- (void)createColorPicker;
@end
In the controllers .m file:
@interface mockViewController ()
@end
@implementation mockViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createColorPicker];
}
- (void)didReceiveMemoryWarning
{
[ super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)createColorPicker
{
colorPickerLoad *newload = [[colorPickerLoad alloc] init];
[self.view addSubview:newload];
[self.view setNeedsDisplay];
}
@结尾