【问题标题】:Fill tableviews in view with data, swift2用数据填充视图中的表格视图,swift2
【发布时间】:2016-01-06 12:57:51
【问题描述】:

我是 Swift 和 iOS 开发的新手,目前正在开发一个显示联系人详细信息的应用程序。现在这个应用程序有一个 ViewController,它显示联系人详细信息。在属于该 ViewController 的视图中,我有两个表视图,应该显示附加信息。 为了能够处理这些表视图,我将视图控制器设置为

UITableViewDataSource, UITableViewDelegate

并添加了以下方法:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print(tableView)
    print(self.hobbiesTableView)
    if(tableView == self.hobbiesTableView){
        return card.hobbies.count
    } else {
        return card.friends.count
    }
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("hobbycell", forIndexPath: indexPath) as UITableViewCell

    let row = indexPath.row

    if(tableView == self.hobbiesTableView){
        cell.textLabel?.text = card.hobbies[row]
    } else {
        cell.textLabel?.text = card.friends[row].vorname
    }

    return cell
}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true;
}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let editAction = UITableViewRowAction(style: .Normal, title: "Edit") { (rowAction:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
        //TODO: edit the row at indexPath here
    }
    editAction.backgroundColor = UIColor.blueColor()


    let deleteAction = UITableViewRowAction(style: .Normal, title: "Delete") { (rowAction:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
        //TODO: Delete the row at indexPath here
    }
    deleteAction.backgroundColor = UIColor.redColor()

    return [editAction,deleteAction]
}

但是,这些方法都没有被调用过。因此,第一个问题是我错过了什么?第二个问题:我启用编辑的方式是否允许删除这些表视图中的条目?

【问题讨论】:

    标签: ios iphone uitableview uiviewcontroller swift2


    【解决方案1】:

    您需要将表视图的委托和数据源属性设置为视图控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多