【发布时间】:2016-10-19 00:42:41
【问题描述】:
我对 ios 开发很陌生。我有一个包含 2 个部分的表格视图
表格视图:
import UIKit
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{
var people = ["ABC","PQR","LMN"]
var languages = ["Android","Java","C++",".Net"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section==0
{return people.count}
else
{return languages.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
if indexPath.section==0{
cell.textLabel?.text = people[indexPath.row]
}
else{
cell.textLabel?.text = languages[indexPath.row]
}
return cell
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section==0{
title="Names"
}
else{
title="Languages"
}
return title
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
我想让表格视图中的每个项目都可以点击。也就是说,当单击表视图中的项目时,将打开一个新的相应表视图。有人可以帮我吗?
【问题讨论】:
-
您的意思是点击表格视图中的单元格进行导航吗?
-
只需根据 indexPath 在
didSelectRowAtIndexPath函数中合并您需要的内容... -
您想要在点击
Language时显示语言列表。我说的对吗? -
@NiravDoctorwala 是的,这就是我的意思
-
@JigarTarsariya 是的,非常正确
标签: ios xcode swift uitableview