Push View Controller不显示从情节提要中添加的元素 [英] Push View Controller not showing elements added from storyboard
问题描述
好的,到目前为止,我的故事板中有两个视图控制器.一个带有登录"元素,另一个带有用户的家"元素.我打算执行以下操作:当用户单击登录名时,需要进行一些处理,然后应显示在用户的主屏幕上.
Okay, so far I've two view controllers in my storyboard. One with "login" elements and other as "User's home" sort of thing. I am intending to do the following : When user clicks on login, there's a bit of processing and then it should show to user's home screen..
当我通过情节提要进行操作时,我的意思是=控制将登录"按钮拖动到用户的主视图,效果很好.但是我不能使用它,因为我必须处理登录数据.同时还显示了一些动画.因此,我必须以编程方式进行此转换.我在登录按钮的IBAction ::
When I do it via storyboard, i mean = control drag "login" button to user's home view it works fine. But I cant use that as I've to process the login data. It also shows some animation meanwhile. So, I've to do this shift programmatically. I wrote following code in the login button's IBAction ::
HomeViewController *homeView = [[HomeViewController alloc] init];
[self presentViewController:homeView animated:YES completion:NULL] ;
现在,这会将用户带到预期的视图.但是,主视图中的元素(例如标签,导航栏)没有显示.这就是我担心的. (理论上,我可以通过编程方式构建整个视图,但我认为这不是正确的方法,是吗?我想充分利用情节提要的功能,即在情节提要中设计最大的UI并从后端按需使用它们他们工作.)
Now, this takes user to the intended view. However, the elements in the homeview (say a label, navigation bar are not being shown. And thats what my worry is. (In theory, I can build entire view programatically but i think thats not the proper way of doing this, is it ? I want to make use of storyboard functionality in full i.e. design maximum UI in storyboard and use them from the backend how you want them to work.)
我该怎么做?
干杯.
PS:我打算增加一些视图控制器,所以目前我还没有想到导航控制器.不知道,如果我应该使用它.
PS : I intend to add few more view controllers so at the moment i didn't think of navigation controller. not sure, if i should use it.
推荐答案
使用您应该使用的故事板:
Using storyboards you should be using:
UIViewController *homeView = [self.storyboard instantiateViewControllerWithIdentifier:@"someID"];
[self presentViewController:homeView animated:YES completion:NULL] ;
然后将ID设置为情节提要中的视图控制器,如下所示:
Then set the ID to the view controller in storyboard like so:
此外,如果您愿意,完全用代码设计UI绝对没有错.我个人更喜欢它.它比接口构建器提供了更多的灵活性.
Additionally, if you wish to there is absolutely nothing wrong with designing your UI entirely in code. Personally I prefer it. It gives you much more flexibility than interface builder.
这篇关于Push View Controller不显示从情节提要中添加的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!