使用 xib 添加 UIView 子类到 UIViewController
我在这里做错了什么?
创建:
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
- XIB 文件将其文件所有者设置为 CustomTab 的类,连接视图
在我的 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];
}
中子视图不会出现在屏幕上。我缺少什么?
What am I doing wrong here?
Created:
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
- XIB file set its files owner to be CustomTab's class, hooked up the view
In my UIViewController class
- (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];
}
The subview doesnt appear on the screen. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nib 文件不会自动将其自身绑定到您的 UIView。如果您的视图是所有者,我想您可以在初始化视图后使用
NSBundle
接口的loadNibNamed:owner:
来加载您的视图。The nib file does not bind itself to your UIView automatically. If your view is owner, I guess you can use
loadNibNamed:owner:
ofNSBundle
interface to load your view after your have init your view.