我試圖添加一個UIButton到一個UIView,但我在運行時得到這個錯誤。嘗試添加一個UIButton到一個UIView,但得到NSInvalidArgumentException',原因:' - [UIView addSubView:]:無法識別
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
!!!不好了!我不應該犯這種錯誤。非常感謝你。 – tommi
如果解決了這個問題,請回答@csl,謝謝! – Madhu
剛剛做到了!感謝您的提醒! @Madhumal Gunetileke – tommi