我有一个问题,设定目标为一个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。第一个解决方案不起作用,但第二个解决方案是现货。 – jonnycage 2012-02-29 20:45:15