简体   繁体   English

未在情节提要中的自定义对象上调用ViewDidLoad

[英]ViewDidLoad not called on custom objects in Storyboard

I finally made the switch to Storyboards and i am having issues loading custom controllers which was pretty easy to do when using interface builder. 我终于切换到情节提要,并且在加载自定义控制器时遇到了问题,这在使用界面生成器时非常容易做到。

I have ViewControllerOne with two components: A UIView and UITableView as the subview. 我有两个组成的ViewControllerOne :一个UIViewUITableView作为子视图。

I want the UITableView to be controlled by a custom tableview controller. 我希望UITableView由自定义tableview控制器控制。 If this was Interface builder i would have dropped a tableview controller onto the XIB, linked to the custom controller and made the connections and it would have been done. 如果这是“接口”构建器,我将把一个tableview控制器放到XIB上,链接到定制控制器并进行连接,就可以完成了。

Using storyboard, i don't believe its possible to drop a UIViewController/UITableViewController onto a scene which already has a view controller, i relied on Objects to achieve this. 使用情节提要,我认为无法将UIViewController / UITableViewController放到已经具有视图控制器的场景上,我依靠Objects来实现这一点。

So i added a Object onto the scene and linked it to my custom tableview controller. 因此,我在场景上添加了一个Object并将其链接到我的自定义tableview控制器。 I set up delegate/date source for my UITableView to point to the custom controller. 我为UITableView设置了委托/日期源,以指向自定义控制器。 I finally connected the UITableViews outlet to the custom controller. 最后,我将UITableViews插座连接到自定义控制器。

When i compile this, the custom controllers delegate (for the table view) gets called but the viewDidLoad is never called. 当我对此进行编译时,将调用(针对表视图的)自定义控制器委托,但从未调用过viewDidLoad。

The only way i can invoke viewDidLoad is if i move the UITableView out of ViewControllerOne. 我可以调用viewDidLoad的唯一方法是将UITableView从ViewControllerOne中移出。 My understanding was that even though there is one view controller for a scene i can still manipulate the subviews using custom controllers. 我的理解是,即使场景有一个视图控制器,我仍然可以使用自定义控制器来操作子视图。

Am i misunderstanding something or is there is a solution for this ? 我是否误解了某件事,或者对此有解决方案?

Some screenshots 一些截图 的TableView

在此处输入图片说明

在此处输入图片说明

There is a bit of magic in that. 那有一些魔术。 Call self.view from awakeFromNib and flow will back to the rails 从awakeFromNib调用self.view ,流程将返回到轨道

- (void)awakeFromNib
{
    [super awakeFromNib];
    // here comes the magic - call self.view and view will load as expected
    NSLog(@"awakeFromNib %@", self.view)
}

you can call it from initWithNibName:bundle: 您可以从initWithNibName:bundle调用它:

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        NSLog(@"awakeFromNib %@", self.view);
    }
    return self;
}

the point is to call self.view because apparently something is done inside. 关键是调用self.view,因为显然内部完成了一些操作。

If I have understood your question correctly: 如果我正确理解了您的问题:

1 Open the storyboard and navigate to the table view controller that you would like to be of your custom type. 1打开情节提要,然后导航到您希望成为自定义类型的表视图控制器。

2 Click on the identity inspector in the right hand side panel. 2单击右侧面板中的身份检查器。

3 Set the class to what it should be. 3将课程设置为应有的水平。

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

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