在我的UIViewController的viewDidLoad方法我如一個UIImageView實例調用階段:添加一個UIImageView作爲一個UIViewController的子視圖,而無需使用IB
stage = [Stage viewWithParent:self];
,並調用此:
- (id)initWithParent:(UIView *)parent {
self = [self initWithFrame:CGRectZero];
if (!self)
return nil;
[parent addSubview:self];
return self;
}
+ (id) viewWithParent:(UIView *)parent {
return [[[self alloc] initWithParent:parent] autorelease];
}
我用前從UIImageView中調用它,並且一切都很好。圖像可見,觸摸事件已啓用並作出響應。從UIViewController我得到一個窗口,但沒有顯示它,並沒有觸及記錄。我錯過了什麼?
任何幫助表示讚賞!
謝謝// :)
看到這個------ http://stackoverflow.com/questions/3321374/cocoa-touch-adding-a-uiimageview-programmatically – 2011-12-08 12:30:24