删除按钮不出现在UITableViewCell中

时间:2015-03-07 16:27:15

标签: swift

在我的程序中,我正在尝试在UITableViewCells上实现滑动删除功能,但即使单元确实在滑动时移动,也不会显示删除按钮。有谁知道为什么?

这是我的代码:

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

    var cell = tableView.cellForRowAtIndexPath(indexPath) as resultsCell

    otherName = cell.usernameLbl.text!
    otherProfileName = cell.profileNameLbl.text!
    self.performSegueWithIdentifier("goToConversationVC", sender: self)

}


override func viewWillAppear(animated: Bool) {
    self.navigationItem.hidesBackButton = true
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return resultsUsernameArray.count
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 120
}

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

    var cell:resultsCell = tableView.dequeueReusableCellWithIdentifier("Cell") as resultsCell

    cell.usernameLbl.text = self.resultsUsernameArray[indexPath.row]
    cell.profileNameLbl.text =       self.resultsProfileNameArray[indexPath.row]

    resultsImageFiles[indexPath.row].getDataInBackgroundWithBlock {
        (imageData: NSData!, error:NSError!) -> Void in

        if error == nil {

            let image = UIImage(data: imageData)
            cell.profileImg.image = image

        }
    }

    return cell

}


@IBAction func logoutBtn_click(sender: AnyObject) {

    PFUser.logOut()
    self.navigationController?.popToRootViewControllerAnimated(true)


}

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

// called when a row is moved
func tableView(tableView: UITableView,
    moveRowAtIndexPath sourceIndexPath: NSIndexPath,
    toIndexPath destinationIndexPath: NSIndexPath) {
        // remove the dragged row's model
        let val = friends.removeAtIndex(sourceIndexPath.row)

        // insert it into the new position
        friends.insert(val, atIndex: destinationIndexPath.row)
}

 func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {
        switch editingStyle {
        case .Delete:
            // remove the deleted item from the model
            friends.removeAtIndex(indexPath.row)

            // remove the deleted item from the `UITableView`
            resultsTable.editing = resultsTable.editing
            resultsTable.editing =  true

            self.resultsTable.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        default:
            return
        }
}
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {

    return .Delete

}

1 个答案:

答案 0 :(得分:0)

您的UITableView太大,因此删除按钮不在屏幕