简体   繁体   English

滑动即可删除单元格

[英]swipe to delete on cell

Getting this error while trying to implement the swipe to delete ima beginner so dont a help with an explanation will be good my todo list saved file import Foundation 尝试实施滑动以删除ima初学者时出现此错误,因此不提供任何帮助将是很好的我的待办事项列表已保存文件导入基础

class TodoListsaved {
class var sharedInstance : TodoListsaved {
    struct Static {
        static let instance : TodoListsaved = TodoListsaved ()
    }

    return Static.instance
}

} }

the cell func 细胞功能

override func tableView(tableView: UITableView, cellForRowAtIndexPath   indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("cell",        forIndexPath: indexPath) as! TableViewCell
    cell.selectionStyle = .None
    let item = todoItems[indexPath.row]
    cell.delegate = self
    cell.toDoItem = item
    return cell

    //modify the cell to have check mark
    if (item.completed) {
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark
    }

    else {

        cell.accessoryType = UITableViewCellAccessoryType.None

    }



  return cell
}

my datasource 我的数据源

import UIKit 导入UIKit

class DataSource: NSObject {

let itenName: String
var completed : Bool
var deadline : NSDate
var UUID :String

init(itenName :String , completed :Bool = false , deadline : NSDate , UUID :String  ) {
    self.itenName = itenName
    self.completed = completed
    self.UUID = UUID
    self.deadline = deadline
    //self.subTitle = subTitle
    }

} } 在此处输入图片说明

When you declared 'TableViewCell' Check that the type of property toDoItem is set to the class you are intending to. 当您声明'TableViewCell'时,请检查属性toDoItem的类型是否设置为您想要的类。 Also check the type of the array todoItems. 还要检查数组todoItems的类型。 They should be same but When I see your bug messages they are not same to each other. 它们应该是相同的,但是当我看到您的错误消息时,它们彼此并不相同。

In your TableViewCell class change the variable toDoItem to type DataSource as follows: 在您的TableViewCell类中,将变量toDoItem更改为键入DataSource,如下所示:

class TablViewCell: UITableViewCell {
 var toDoItem: DataSource?
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM