gpt4 book ai didi

swift - 删除按钮未出现在 UITableViewCell 中

转载 作者:行者123 更新时间:2023-11-28 09:12:16 25 4
gpt4 key购买 nike

在我的程序中,我试图在 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

}

最佳答案

您的 UITableView 太大,因此删除按钮超出了屏幕

关于swift - 删除按钮未出现在 UITableViewCell 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28917080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com