【发布时间】:2012-03-18 06:34:33
【问题描述】:
我在为 UIButton 设置目标时遇到问题:
// 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 并且我无法访问控制器。
知道如何解决这个问题吗?
【问题讨论】:
标签: ios uiscrollview uibutton automatic-ref-counting