根据在swift中select的第一个表格行更改第二个表格内容

我有一个视图与两个表(propertyTypeList&propertyDetailList)和一个文本视图(propertyDetailView)

我想要做的是有propertyDetailList填充基于在propertyTypeList中作出的select的数组,然后有propertyDetailView根据propertyDetailList中的select填充。

我可以使用我的底部函数和indexPath.row查看当前选定的行,但是我无法获得该函数在上面的函数中工作。

这里是我的代码:

class NewProjectView: UIViewController { @IBOutlet weak var propertyTypeList: UITableView! @IBOutlet weak var propertyDetailList: UITableView! @IBOutlet weak var propertyDetailView: UITextView! var testarray = ["test1", "test2"] func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { if tableView == propertyTypeList { return projectSources.count; } else { return testarray.count } } func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"Cell") if tableView == propertyTypeList { cell.textLabel?.text = projectSources[indexPath.row] if indexPath.row == 0 { println("Row 0") } else { println("Not Row 0") } return cell } else { cell.textLabel?.text = testarray[indexPath.row] return cell } } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath, animated: true) println(indexPath.row) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ } 

如何从第二个tableView Func访问indexPath.row?

看起来你的问题有一个错字。 你说:

我有一个视图与两个表(propertyTypeList&propertyDetailList)和一个文本视图(propertyDetailView)

我想要做的是有propertyDetailList根据在propertyDetailList中所做的select填充数组,然后有propertyDetailView根据propertyDetailList中的select填充。

你是不是故意说:“我想要做的是有propertyDetailList填充基于在propertyTypeList中做出的select数组…”这将是更有意义的。

所以你基本上有一个主 – 细节设置,其中propertyTypeList是一个主表视图,propertyDetailList是细节表视图。

我假设这两个表视图都有他们的数据源和委托指向相同的视图控制器。

你需要做的是写你的tableView:didSelectRowAtIndexPath:方法来检查tableView参数。 当用户在tableView中select一行时,该方法将被调用,但tableView参数可以让你找出所选单元格属于哪个表视图。

所以你的代码可能看起来像这样:

 func tableView( tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if (tableView == propertyTypeList) { //Switch the selected item in the detail list } else { //do whatever is appropriate for selecting a detail cell. } }