【问题标题】:my viewcontroller does not fall in the viewdidLoad method我的 viewcontroller 不属于 viewdidLoad 方法
【发布时间】:2019-10-15 13:55:15
【问题描述】:

我有一个问题,我正在学习 swift 编程,我已经学会毫无问题地处理表格和集合,包括使用 alamofire 服务的 cosumo,但是我遇到了一个问题,我在个性化表格视图中有一个集合单元格,设法在集合内单击事件,并通过协议传递我需要的信息将其传递给 ViewController,但是当我加载以下 ViewController (TabsDetailProductViewController) 时,它不会落入 viewDidLoad 上的方法中不跳转到与DetailProductContentViewController连接的已添加的ContentView。也就是说,正如我在使用该方法时所理解的那样。

func ItemClick(position: Int, model: Product) {
        let Storyboard = UIStoryboard(name: "Main", bundle: nil)
        let tabsViewController = Storyboard.instantiateViewController(withIdentifier: "TabsDetailProductViewController") as! TabsDetailProductViewController
        tabsViewController.productModel = model
        self.navigationController?.pushViewController(tabsViewController, animated: true)
    }

我不得不陷入 TabsDetailProductViewController 的 viewLoaded 中,但它跳转到了 DetailProductContentViewController 的 viewLoaded,然后返回到 TabsDetailProductViewController 的 viewLoaded。我需要知道我做错了什么,或者这就是生命周期。

这是我的故事板。

【问题讨论】:

  • 如果您要以编程方式“推送”视图控制器,然后从情节提要中移除 segue,这应该是您的第一步,然后进行更多调试以查看其他情况
  • 嗯,你的意思是图像中的segue,嵌入@MXNMike
  • 好还是一样,继续直接进入 DetailProductContentViewController ,我已经能够证明的是,当我从情节提要中将类删除到 DetailViewController 时,viewDidLoad 中出现了第一个问题TabsDetailProductViewController @MXNMike
  • 好的,首先让我了解您在这里要完成的工作... tabsViewcontroller 处理 SegmentedController 对吗?分段控制器有一个表格视图,表格视图中的某些行有一个集合视图,这是正确的吗?然后,当您单击其中一个 collectionViewCells 时,您会打开 detailsViewController? @dbenitobaldeon

标签: ios swift uiviewcontroller uinavigationcontroller uistoryboardsegue


【解决方案1】:

简答

I need to know what I'm doing wrong?

什么都没有

or maybe this is the life cycle.

是的

说明

根据苹果官方文档viewdidload

在视图控制器将其视图层次结构加载到内存后调用此方法。

在您的情况下,为了完全加载TabsDetailProductViewControllerview hierarchy,必须首先加载DetailProductContentViewController,因为它在TabsDetailProductViewController 的视图层次结构中是containment 的结果

因此DetailProductContentViewControllerviewdidload 将在TabsDetailProductViewControllerviewdidload 之前调用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多