简体   繁体   English

以编程方式将UIButton添加到自定义ViewController的情节提要

[英]Programmatically add UIButton to custom ViewController with storyboard in place

I've successfully implemented walkthrough screens by following AppCoda's Create UIPageViewController Using Storyboard tutorial . 通过遵循AppCoda的使用Storyboard教程创建UIPageViewController,我已经成功实现了演练屏幕。 At the end of the example a UIPageControl is created in code and now I'm trying to add a UIButton the same way, programmatically. 在示例的最后,用代码创建了一个UIPageControl,现在我试图以编程方式以相同的方式添加一个UIButton。

The button appears if added via storyboard but otherwise none of these have worked for me when (individually) added to my viewDidLoad : 如果通过情节提要添加按钮,则会出现该按钮,但是当(单独)添加到我的viewDidLoad时,这些按钮都不对我viewDidLoad

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
// [self.view addSubview:button];
// [self.view bringSubviewToFront:button];
// [self.view insertSubview:button atIndex:0];
// [self.view insertSubview:button atIndex:[self.view subviews].count + 1];
// [self.view insertSubview:button aboveSubview:self.view];
// [self initButton:button];

There's got to be something relatively simple that I'm missing. 我一定缺少一些相对简单的东西。 Should I just stick to Android? 我应该坚持使用Android吗?

Just uncomment [self.view addSubview:button]; 只是取消注释[self.view addSubview:button]; line and it should work. 线,它应该工作。 If it doesn't work I believe you have some other view added on top of self.view which hover over your button. 如果它不起作用,我相信您会在self.view之上添加一些其他视图,将其悬停在按钮上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM