开发者

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.

NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized

XCode also warns me that that

Instance method '-addSubView:' not found (return type defaults to 'id')

This is my code:

 UIView *trackPaneView = [[[UIView alloc开发者_JS百科] 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:

(capitalisation error)


It’s -addSubview, not -addSubView. Method names are case-sensitive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜