试图添加一个UIButton到一个UIView但得到NSInvalidArgumentException',原因:' – :无法识别
我想添加一个UIButton到一个UIView,但我在运行时得到这个错误。
NSInvalidArgumentException',原因:' – [UIView addSubView:]:无法识别
XCode也警告我说
实例方法'-addSubView:'未find(返回types默认为'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:
not addSubView:
(大写错误)
它是-addSubview
,而不是-addSubView
。 方法名称区分大小写。