![](/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.