私はUIButtonのための目標を設定し、問題が生じています:なぜこのオブジェクトはARCで時期尚早に割り当てを解除されていますか?
// TestViewController.m
@implementation TestViewController
@synthesize scrollContentView
- (void)viewDidLoad
{
[super viewDidLoad];
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.scrollContentView addSubview:secondViewController.view];
}
@end
// SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self action:@selector(button1Click:) forControlEvents:UIControlEventTouchUpInside];
button1.frame = CGRectMake(20, 45, 280, 40);
[self.view addSubview:button1];
}
- (IBAction)button1Click:(id)sender
{
NSLog(@"test");
}
私は次のエラーメッセージを取得]ボタンをクリックしたときに問題がある:
[SecondViewController performSelector:withObject:withObjectを:]:メッセージ割り当て解除インスタンスに送信 0x685c050
(lldb)
私はUIScrollViewにビューを渡しているため、コントローラにアクセスできないという問題があると想定しています。
これを解決する方法はありますか?
ありがとうNJones。最初の解決策は機能しませんでしたが、2番目の解決策がありました。 – jonnycage