没用.xib文件创建视图,使用了loadview方法,但是当调用loadView的时候,view的框架还未知。因此我建立的view层,没有具体框架。问题是,能不能用[[UIView alloc] init]
或者[[UIView alloc] initWithFrame:CGRectZero]
或者其他方法,初始化未知框架的view?
代码:
- (void)loadView
{
UIView *containerView = [[UIView alloc] init];
// or
// UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
// or something else?
// ...
self.view = containerView;
[containerView release];
}
- (id)initWithFrame:
是用UIView的指定初始化程序,应该使用这个,矩形尺寸为0。
UIView *containerView = [[UIView alloc] init];
// or
// UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
这两种写法有什么区别么?感觉一样呀。