2010-04-01 73 views
1

我想通过编程方式来配置视图。我有一个UIViewController,并希望添加一个UIButton到它的视图。访问一个viewControllers视图

嗯,我创建的按钮:

UIButton *newViewButton = [[UIButton alloc] initWithFrame:CGRectMake(baseX + viewPlusX, baseY + viewPlusY, viewWidth, viewHeight)]; 
[newViewButton setTitle:@"View" forState:UIControlStateNormal]; 
[newViewButton setTag:(int)key]; 
[newViewButton addTarget:myViewController action:@selector(viewButton:) forControlEvents:UIControlEventTouchUpInside]; 

,但试图将它添加到视图

[myViewController.view addSubview:newViewButton]; 

我得到的错误时

error: expected ':' before":" token 

任何线索,我是什么做错了

个问候

+0

你真的应该开始接受答案,帮助你。您通过点击有用答案左上角的复选标记来接受答案。 – Till 2010-04-20 15:27:02

回答

2

@selector(viewButton:sender)应该读@selector(viewButton:sender:)

3

使用

[myViewController.view addSubview:newViewButton]; 
+0

嗨,奥莱,其实我打错了我的求救声音(只是更新了它)。这是我如何得到它,并在哪里我得到上述错误... – iFloh 2010-04-01 10:25:55

+0

它似乎是“myViewController.view”引用导致错误。 NSLog显示错误“访问未知”视图“类方法”。 不明白这一点,因为myViewController的类型是UIViewController。 – iFloh 2010-04-01 11:41:53

+0

好的,发现问题......笨...通过了课程,而不是对象.... – iFloh 2010-04-01 11:51:15