如何仅在显示容器视图时如何运行您的API?

问题描述 投票:-1回答:1

我正在一个视图控制器中使用5个容器的视图。所有容器视图均具有相同的大小(相同的宽度和相同的高度)。在不同的容器视图上执行不同的API。

我正在实现的方法是根据存在的按钮显示和隐藏容器视图。例如:单击一个按钮时,将显示一个容器视图,而其他则被隐藏。

我面临的问题是,在加载视图控制器时,将同时调用所有容器视图中的所有api。我希望它在显示容器视图时运行。有人可以帮我吗?

ios swift uicontainerview
1个回答
1
投票

尝试此一个

我认为您会找到类似的东西。

1)在yourContainerViewController中创建APICaliing和数据重载功能。

2)从YourMainViewController childViewControllers中找到yourContainerViewController。

3)调用APICalling函数。

@IBAction func btnClickEvent(_ sender: UIButton) { 

    //Find yourContainerViewController from your all childViewControllers
    for vcObj in self.childViewControllers{
        if vcObj.isKind(of: yourContainerViewController.self){
            // Here your api call and reload data inside this function
            // apiCallFunction() Function create in you yourContainerViewController and put api calling and data reload code in this function.
            (vcObj as! yourContainerViewController).apiCallFunction() 
            break
        }
    }

}

乐于助您:)

© www.soinside.com 2019 - 2024. All rights reserved.