我在这里做错了什么?
创建:
CustomTab.h
#import <UIKit/UIKit.h>
@interface CustomTab : UIView {
IBOutlet UIView *view;
}
@property (nonatomic, retain) IBOutlet UIView *view;
@end
CustomTab.m
#import "CustomTab.h"
@implementation CustomTab
@synthesize view;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
- (void)dealloc {
[super dealloc];
}
@end
在我的UIViewController类
中- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 320, 40); // Replacing with your dimensions
CustomTab *myObj = [[CustomTab alloc] initWithFrame:frame];
[self.view addSubview:myObj.view];
[myObj release];
}
子视图不会出现在屏幕上。我错过了什么?
答案 0 :(得分:2)
nib文件不会自动将自身绑定到您的UIView。如果您的视图是所有者,我猜您可以在初始化视图后使用loadNibNamed:owner:
NSBundle
界面加载视图。