【发布时间】:2016-08-05 17:53:44
【问题描述】:
我在情节提要中创建了一个包含 11 行的 tableview。我希望能够点击每一行并将其打开到它自己的 tableview 控制器中,我将在其中存储数据,具体取决于所点击的行。
var array = ["row 1", "row 2", "row 3", "row 4", "row 5", "row 6", "row 7", "row 8", "row 9", "row 10", "row 11"]
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("prototypeCellIdentifier", forIndexPath: indexPath)
cell.textLabel?.text = array[indexPath.item]
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
return cell
}
这是我为创建行所做的。
【问题讨论】:
-
UITableViewDelegate 方法
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) -
学习阅读 Apple 文档。这一切都在里面。或搜索互联网。互联网上有无数关于此的教程和示例。
-
@dasdom 我想你可能正在做点什么。如果每个人都这样做,并且堆栈溢出不必存在。
-
@icestorm0806 stackoverflow.com/help/how-to-ask
标签: ios swift uitableview