2016-07-11 90 views
0

我有一个评论列表。如果是我的用户自己的评论,当用户从左到右滑动时,删除选项将被启用。删除注释后,它将重新加载表。用户可以在同一页面上添加新评论,那个时候,它也会重新加载表格。Swift自定义滑动表格视图动态中的单元格问题

我使用this repository and using this

问题是;

它正在工作,但很少有bug。让我们来解释一下这个案例。如果它不是我的评论,当我刷卡时也显示删除选项,因为我添加了新评论并删除了一些评论。在这种情况下,先前添加的滑动单元格不会被删除。我认为是这种情况。无法实现它。

当我滚动评论时,它以错误的方式显示删除选项。我用滑动检查了用户标识。请指导我。它正常工作。目前的要求是显示删除图标。

这是我的代码:

class CustomCommentCellTableViewCell: PKSwipeTableViewCell { 

@IBOutlet weak var timelineLabel : UILabel! 
@IBOutlet weak var commentMsg  : UILabel! 
@IBOutlet weak var commenterName : UILabel! 
@IBOutlet weak var profName  : UILabel! 
@IBOutlet weak var proIcon  : UIImageView! 
var commentCount : Int?; 
var userID : String? 

override func awakeFromNib() { 
    super.awakeFromNib() 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
    // Configure the view for the selected state 
} 


func configureCell(row:Int, userID: String,msg: String) { 
    // self.lblTitle.text = strToSet 
    self.userID = userID; 
    self.commentCount = row; 
    print("row ==== :\(row) =====:\(msg)") 
    print(":\(userID) ==loged=:\(Globals.sharedInstance.userId) =====:\(userID == Globals.sharedInstance.userId)") 

    if(userID == Globals.sharedInstance.userId){ 
     self.addRightViewInCell() 
    }else{ 
     self.resetCellState() 
    } 


} 

func addRightViewInCell() { 
    //Create a view that will display when user swipe the cell in right 
    let viewCall = UIView() 

    viewCall.backgroundColor = UIColor(red: 254.0/255.0, green: 53.0/255.0, blue: 63.0/255.0, alpha: 1.0) 
    viewCall.frame = CGRectMake(0, 0,CGRectGetHeight(self.frame)+20,CGRectGetHeight(self.frame)) 
    //Add a label to display the call text 

    //Add a button to perform the action when user will tap on call and add a image to display 
    let btnCall = UIButton(type: UIButtonType.Custom) 
    btnCall.frame = CGRectMake((viewCall.frame.size.width - 40)/2,viewCall.frame.size.height/2,40,40) 
    btnCall.setImage(UIImage(named: "ico_delete"), forState: UIControlState.Normal) 
    btnCall.addTarget(CommentViewController(), action: #selector(CommentViewController.confirmDelete), forControlEvents: UIControlEvents.TouchUpInside) 

    viewCall.addSubview(btnCall) 


    //Call the super addRightOptions to set the view that will display while swiping 
    super.addRightOptionsView(viewCall) 

} 

func callButtonClicked(){ 
    //Reset the cell state and close the swipe action 

    self.resetCellState() 
}} 

删除和添加新的评论后,我总是打电话重装表。

请指导我

+0

为什么你不只是使用'UITableViewRowAction'来做到这一点? – NRitH

+0

要求显示的图标用于删除当用户滑动但该选项不能在内置功能 – Piraba

+0

你好检查这个存储库https://github.com/Dudi00/SwipeableTableViewCell也许可以帮助你 –

回答

2

你不能使用默认的iOS删除这个。但不建议将图像添加到此默认的删除按钮,只有文本可以更改。

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return true // if deletable else false 
} 

func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? { 
    return "Del" 
} 

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle = .Delete { 
     // perform the delete and reload table 
    } 
} 
+0

是的。这是可能的。它的工作。但目前的要求是显示图标(删除),而不是文字。 – Piraba

0

尝试覆盖单元格的- (void)prepareForReuse方法并删除此附加视图。

相关问题