【发布时间】:2016-06-01 02:08:59
【问题描述】:
我一直在寻找如何做到这一点的答案,但似乎没有什么是直截了当的,或者用户想要做一些不同的事情(比如选择多个单元格)。
背景:
我正在制作一个应用程序,用于每天检索不同职业的报价,例如阅读、园艺、运动。我有一个带有 3 个选项卡的 UITabBarController。
第一个标签 = 报价;第二个选项卡 = 类别;第三个选项卡 = 设置 *
设置选项卡是一个 UITableView,有 3 个部分,每个部分有 2 个单元格。
问题:我想让每个单元格去不同的目的地。第一部分中的第一个单元格将只是一个带有滑块的视图控制器(用于更改文本颜色的颜色滑块)(稍后会介绍)。我怎样才能做到这一点?
import UIKit
class settingsTab: UIViewController, UITableViewDelegate {
struct Objects {
var sectionName : String!
var sectionObjects : [String]!
}
var objectsArray = [Objects]()
override func viewDidLoad() {
super.viewDidLoad()
objectsArray = [Objects(sectionName: "Options", sectionObjects: ["Change color of text" , "Notifications"]),Objects(sectionName: "Extras", sectionObjects: ["Remove ads" , "Restore purchases"]),Objects(sectionName: "Support", sectionObjects: ["Rate this app" , "Email developer"]), Objects(sectionName: "Jordan Norris - Quote Daily 2016", sectionObjects: [])]
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell!
cell.textLabel?.text = objectsArray[indexPath.section].sectionObjects[indexPath.row]
cell.backgroundColor = UIColor.cyanColor()
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objectsArray[section].sectionObjects.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return objectsArray.count
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return objectsArray[section].sectionName
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
}
这是settingsTab.swift,建立TableViewController的地方。如果您需要更多信息,只需评论您想要添加的内容,我会立即编辑此帖子。提前谢谢!
【问题讨论】:
标签: swift uitableview didselectrowatindexpath sections