gpt4 book ai didi

ios - PageMenu 如何动态(以编程方式)添加 View Controller ?

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:22 24 4
gpt4 key购买 nike

我希望我的应用看起来像下图。

我正在使用 PageMenu来完成这个结果。数据是从 Web API 中获取的。我想根据 Web API 响应的天数动态创建 View Controller ,以便每一天都可以有一个 View Controller ,以便它可以显示当天的时间表。我怎样才能做到这一点?

enter image description here

最佳答案

从您自己提供的链接中读取它有:

// Array to keep track of controllers in page menu
var controllerArray : [UIViewController] = []

// Create variables for all view controllers you want to put in the
// page menu, initialize them, and add each to the controller array.
// (Can be any UIViewController subclass)
// Make sure the title property of all view controllers is set
// Example:
var controller : UIViewController = UIViewController(nibName: "controllerNibName", bundle: nil)
controller.title = "SAMPLE TITLE"
controllerArray.append(controller)

所以您要做的是:拥有一个返回[dailyModel] 的函数。你的 dailyModel 看起来像这样:

struct dailyModel {
let programStartingTime : String // 6:45
let item : [item] // [(Maghrib & Isha Prayer, 20, 0),(Ziarat-e-Ashura, 20, 1), ...otherItems...]
}

struct item{
let duration : Int? //minutes
let name : String // Maghrib and Isha prayers
let row : Int? // 0
}

然后循环遍历 dailyModel 并使用它的参数实例化 & 填充 viewcontroller 然后append 每个教程都在做。

这不是最好的代码,但我希望你能理解。

关于ios - PageMenu 如何动态(以编程方式)添加 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40615317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com