![](/img/trans.png)
[英]UIButton not Working when the UIview is presented by addsubView
[英]Trying to add a UIButton to a UIView but getting NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized
我正在尝试将UIButton添加到UIView,但在运行时遇到此错误。
NSInvalidArgumentException',原因:'-[UIView addSubView:]:无法识别
XCode还警告我,
找不到实例方法“ -addSubView:”(返回类型默认为“ id”)
这是我的代码:
UIView *trackPaneView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 100)] autorelease];
[trackPaneView setBackgroundColor:[UIColor blueColor]];
UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 10, 100, 30)];
[testButton setTitle:@"AWESOME" forState:UIControlStateNormal];
[trackPaneView addSubView:testButton]; //the error coming form this line
方法是addSubview:
不是addSubView:
(大写错误)
它是-addSubview
,不是-addSubView
。 方法名称区分大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.