【发布时间】:2011-02-25 15:40:26
【问题描述】:
大家好,我有一个简单的 UIView,里面有一个 UIButton,调用一个方法,我试图尽可能地简化它,但总是遇到同样的错误:
2011-02-25 10:33:23.423 USOpenTimeLine[21288:207] -[CALayer buttonClicked:]:无法识别的选择器发送到实例 0x4d2a020 2011-02-25 10:33:23.425 USOpenTimeLine[21288:207] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[CALayer buttonClicked:]:无法识别的选择器发送到实例 0x4d2a020” * 首次抛出时调用堆栈:
我的代码如下:
-(UIView *)createView:(NSArray *)_data{
UIView *_view = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 1024, 768)];
pageData = [[NSMutableArray alloc] init];
self.imageData = _data;
[_view setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:0 alpha:1.0]];
[self addSubview:_view];
UIButton *_button1= [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
_button1.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[_button1 setTitle:@"Play" forState:UIControlStateNormal];
_button1.backgroundColor = [UIColor clearColor];
[_button1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[_view addSubview:_button1];
[_button1 release];
[_view release];
return _view;
}
- (IBAction)buttonClicked:(id)sender
{
NSLog(@"Hi!");
}
我这辈子都想不通这里发生了什么…… 任何帮助或见解将不胜感激! 谢谢
【问题讨论】:
-
好的,我想通了,我太早释放父视图了。
标签: objective-c ipad uiview uibutton