ストーリーボードを使用し、ARCをオンにしたiOS5プロジェクトがあります。
ストーリーボードにthisViewControllerクラスのビューがあり、そこにドラッグしてクラスthisViewを指定した小さなサブビューがあります。
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;
}