[英]Fill tableviews in view with data, swift2
我是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]
}
但是这些方法都没有被调用过。 因此,第一个问题是我想念什么? 第二个问题:启用编辑的方式是否允许删除那些表视图中的条目?
您需要将表视图的委托和dataSource属性设置为视图控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.