mercredi 4 mai 2016

how to add checkmark in tableview swift

I'm trying to show checkmark on tableview cell, but the checkmark appears only sometimes and it disappears when I scroll.

Below the code:

 
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("vvxxx12", forIndexPath: indexPath)
    
        // Configure the cell...
        
    cell.textLabel?.text = self.dataArray[indexPath.row] as? String //in dataArray values are stored
             

       if dataArray.containsObject(indexPath)
       {
            cell.accessoryType = .Checkmark
       }
       else {
            cell.accessoryType = .None
        }
       return cell
         }

        func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            if let cell = tableView.cellForRowAtIndexPath(indexPath) {
                if cell.accessoryType == .Checkmark {
                    cell.accessoryType = .None
                   
                } else {
                    cell.accessoryType = .Checkmark
                   
                }
            }    
        }

Aucun commentaire:

Enregistrer un commentaire