开发者

Access a viewControllers View

I am trying to get to grips with programmatically configuring views. I have a UIViewController and want to add a UIButton to its view.

Well, I created the button:

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];

but when trying to add it to the view

[myViewController.view addSubview:newViewButton];

I get the error

error: expected ':' before":" toke开发者_StackOverflow社区n

any clue what I am doing wrong

regards


Use

[myViewController.view addSubview:newViewButton];


@selector(viewButton:sender) should read @selector(viewButton:sender:)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜