UIViewから継承するGraphicViewクラスがあります。そのinitWithFrame
方法は次のとおりです。ビューがプロパティの場合、InitWithFrameは実行されません。
@implementation GraphicsView
- (id)initWithFrame:(CGRect)frameRect
{
self = [super initWithFrame:frameRect];
// Create a ball 2D object in the upper left corner of the screen
// heading down and right
ball = [[Object2D alloc] init];
ball.position = [[Point2D alloc] initWithX:0.0 Y:0.0];
ball.vector = [[Vector2D alloc] initWithX:5.0 Y:4.0];
// Start a timer that will call the tick method of this class
// 30 times per second
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/30.0)
target:self
selector:@selector(tick)
userInfo:nil
repeats:YES];
return self;
}
私はViewController.xib
へのUIView(クラス=グラフィック・ビュー)を追加しました。そして、私はプロパティとしてGraphicView
を追加しました:
@interface VoiceTest01ViewController : UIViewController {
IBOutlet GraphicsView *graphView;
}
@property (nonatomic, retain) IBOutlet GraphicsView *graphView;
- (IBAction)btnStartClicked:(id)sender;
- (IBAction)btnDrawTriangleClicked:(id)sender;
@end
しかし、このコードでは動作しません、私はそれが動作するために[graphView initWithFrame:graphView.frame]
を呼び出す必要があります。
- (void)viewDidLoad {
[super viewDidLoad];
isListening = NO;
aleatoryValue = 10.0f;
// Esto es necesario para inicializar la vista
[graphView initWithFrame:graphView.frame];
}
いいですか?それを行う良い方法はありますか?
GraphicViewをプロパティとして追加すると、なぜinitWitFrameが呼び出されないのか分かりません。
ありがとうございます。 initWithCoderをどのようにオーバーライドできますか?私はインターネットで検索していますが、例は見つかりませんでした。再度、感謝します。 – VansFannel
' - (id)initWithCoder:(NSCoder *)coder' ViewController .mファイルのXcodeで入力を開始すると、自動的に自動補完されます。 – jv42
ありがとうございます。私はまた、次のようなものを追加する必要があると思います: 'if((self = [super initWithCoder:coder])){' – VansFannel