我有一個使用故事板和ARC的iOS5項目。爲什麼我的UIButton不顯示在我的視圖中?
我有一個故事板與類thisViewController視圖,並在那裏我有一個較小的子視圖,我拖入並給它類thisView。
此視圖有一個自定義drawRect函數,它工作並繪製我想要的。 但我也想動態添加按鈕,所以我會在thisView的initWithFrame方法如下所示添加它們:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"This is called <3");
UIButton *btn= [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 50, 50);
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"Play" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
[self bringSubviewToFront:btn]; // last thing I tried, didn't work, thought z-index was to low or something
}
return self;
}
功能正在因爲NSLog的顯示屏叫,但按鈕是無處可尋
- 編輯 -
額外信息:
ThisView.h
@interface RadarView : UIView <CLLocationManagerDelegate>{
CLLocation *currentLocation;
}
你試過'[self.view addSubview:btn];'? – janusbalatbat 2012-07-23 08:44:58
@janusfidel我得到一個錯誤'屬性視圖找不到對象的類型ThisView *。但這是正常的權利?導致對象本身是一個視圖?沒有? – Spyral 2012-07-23 08:47:53
它取決於你有什麼超類,你的超類在這裏? – janusbalatbat 2012-07-23 08:49:13