【发布时间】:2017-07-29 17:42:58
【问题描述】:
我花了几个小时试图找到解决方案,但我总是一无所获。
我正在尝试在 TableView 内创建一个段控件,该段控件具有一个 CustomCell 用于段控件的两个视图。
https://www.youtube.com/watch?v=dw7kytoA3KU&t=198s 是我想要完成的一个完美示例,但用户插入了 1 个 CustomCell 并且代码有点混乱。
我的第一个 CustomCell 包含图像、名称和数字。 我的第二个 CustomCell 只包含一个图像。
所以我的问题是......
-
我应该如何为两个CustomCell创建两个数组?
我正在尝试完成的示例
自定义单元格 1:
let names = ["Pizza","Soup","Tacos","Chicken", "Beef"]
let image = [UIImage(named: "Pizza1"), UIImage(named: "Soup1"), UIImage(named: "Tacos1"), UIImage(named: "Chicken1"), UIImage(named: "Beef1")]
let numbers = ["1", "2", "3", "4", "5"]
自定义单元格 2:
let photo = [UIImage(named: "Pic1"), UIImage(named: "Pic2"), UIImage(named: "Pic3")]
-
根据我的研究,当需要将 CustomCell 文件和两个 CustomCell 调用到我的代码中时,这是否正确?
let nib = UINib(nibName: "CustomCell", bundle: nil) tableView.register(nib, forCallReuseIdentifier: "CustomCell1") tableView.register(nib, forCallReuseIdentifier: "CustomCell2") -
为此应该返回什么?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int -
这部分是我对输入内容感到困惑的地方
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
总结:我正在尝试在具有 2 个 CustomCells 的 tableView 中创建一个段控件。我希望该段的第一个视图是具有图像、名称和编号的 CustomCell。该段的第二个视图只有图像。
谢谢!
【问题讨论】:
-
一个TableView...里面...一个段控件?
-
@Matthew ...我的错,Tableview 中的 UISegmented 控件
标签: arrays swift tableview uisegmentedcontrol custom-cell