【问题标题】:Custom Cell Image as AccessoryType in Swift将单元格图像自定义为 Swift 中的 AccessoryType
【发布时间】:2015-03-06 12:25:01
【问题描述】:

您好,我希望获得一个自定义单元配件类型来在图像之间进行更改。现在它是一个复选标记,然后没有复选标记。我使用 Parse 作为我的后端,每个用户都有关注者并且关注多个人。我想将其更改为在两个图像之一之间显示以供关注或+关注。现在它已设置为复选标记。我当前的代码在我的下面有没有人有任何建议?

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

    var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

    if cell.accessoryType == UITableViewCellAccessoryType.Checkmark {

        cell.accessoryType = UITableViewCellAccessoryType.None

        var query = PFQuery(className:"followers")
        query.whereKey("follower", equalTo:PFUser.currentUser().username)
        query.whereKey("following", equalTo:cell.textLabel?.text)
        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]!, error: NSError!) -> Void in
            if error == nil {

                for object in objects {

                    object.delete()

                }
            } else {
                // Log details of the failure
                println(error)
            }
        }

    } else {

        cell.accessoryType = UITableViewCellAccessoryType.Checkmark

        var following = PFObject(className: "followers")
        following["following"] = cell.textLabel?.text
        following["follower"] = PFUser.currentUser().username

        following.save()

    }

}

【问题讨论】:

    标签: ios parsing swift custom-cell tableviewcell


    【解决方案1】:

    对我来说,我可能是 UIButton 的子类,并将图像设置为默认状态和选定状态。

    然后执行动作:

        @IBAction func follow(sender: UIButton) {
    
            sender.selected = !sender.selected
    
            switch sender.selected {
            case true :
                print("do start follow")
            case false :
                print("cancel follow")
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多