Swift UITableView获取选定的表项

ster位

我打算在一个具有不同数据的两个不同类的一个ViewController中连接两个UITableView,然后选择该项目,但我无法使其工作

AppController.swift

类AppController:UIViewController {

@IBOutlet weak var projects_TableView: UITableView!  
@IBOutlet weak var hours_TableView: UITableView!

var projects_DataSource: TableViewProjects?
var hours_DataSource: TableViewHours?

override func viewDidLoad() {
    super.viewDidLoad()

    projects_DataSource = TableViewProjects()
    hours_DataSource = TableViewHours()
    projects_TableView.dataSource = projects_DataSource
    hours_TableView.dataSource = hours_DataSource

    println("Table Sources Success")
}


func TableProjectsSelected() {
    println("Selected Project Table")

    self.performSegueWithIdentifier("projectTable", sender: AnyObject?())
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "projectTable" {
            //do stuff
            println("projectTable ID")
        }
    }

TableViewProjects.swift

var items: [String] = ["Project 1", "Project 2", "Project 3"]

override init() {
    super.init()
}


//TABLE FUNCTIONS
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return items.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "projectcell")

    cell.textLabel!.text = items[indexPath.row]

    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    println("Select From Class")

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let appController: AppController = storyboard.instantiateViewControllerWithIdentifier("SelectProjectAndHour") as! AppController

    appController.TableProjectsSelected()

}

我无法从TableViewProjects.swift中选择的项目获得响应

也许您应该在下面添加这些代码:

projects_TableView.delegate = projects_DataSource
hours_TableView.delegate = hours_DataSource

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章