[英]Trying to add a UIButton to a UIView but getting NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized
I'm trying to add a UIButton to a UIView but I'm getting this error at runtime. 我正在尝试将UIButton添加到UIView,但在运行时遇到此错误。
NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized NSInvalidArgumentException',原因:'-[UIView addSubView:]:无法识别
XCode also warns me that that XCode还警告我,
Instance method '-addSubView:' not found (return type defaults to 'id') 找不到实例方法“ -addSubView:”(返回类型默认为“ id”)
This is my code: 这是我的代码:
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
The method is addSubview:
not addSubView: 方法是addSubview:
不是addSubView:
(capitalisation error) (大写错误)
It's -addSubview
, not -addSubView
. 它是-addSubview
,不是-addSubView
。 Method names are case-sensitive. 方法名称区分大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.