2016-04-09 10 views
1

Birkaç ileti okudum, ancak kendi kodumda nasıl uygulandığını göremiyorum. Nesne kitaplığından sürüklediğim bir düğme çubuğu (Düzenleme) var; İşi yapar, ancak düzenleme modundayken 'Bitti'yi görüntülemek isterim - herhangi bir yardım çok takdir edilecektir. Benim kod şöyle görünür:Düzenleme yaparken 'Düzenle' düğmem nasıl 'Done' durumuna geçebilir?

@IBAction func editButton(sender: AnyObject) { 
    self.editing = !self.editing { 

// Override to support conditional editing of the table view. 
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return false if you do not want the specified item to be editable. 
    return true 
} 



// Override to support editing the table view. 
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle == .Delete { 

     // Delete the row from the data source 
     lessons.removeAtIndex(indexPath.row) 
     saveLessons() 
     tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 

    } else if editingStyle == .Insert { 

     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    }  
} 


// Override to support rearranging the table view. 
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { 

    let itemToMove = lessons[fromIndexPath.row] 

    lessons.removeAtIndex(fromIndexPath.row) 

    lessons.insert(itemToMove, atIndex: toIndexPath.row) 

    saveLessons() 

} 

cevap

2

geçersiz kılma setEditing

override func setEditing(editing: Bool, animated: Bool) { 
    super.setEditing(editing, animated:animated) 
    if editing == true { 
    // set title of the bar button to 'Done' 
    editBarButton.title = "Done"  
    } else { 
    // set title of the bar button to 'Edit' 
    editBarButton.title = "Edit" 
    } 
} 

veya daha kısa Üçlü Koşullu Operatör

override func setEditing(editing: Bool, animated: Bool) { 
    super.setEditing(editing, animated:animated) 
    editBarButton.title = editing ? "Done" : "Edit" 
} 
+0

sayesinde Vadian kullanarak - Eğer başlık ayarlarım nasıl? – Laroms

+1

Düğmeye bir referansa ihtiyacınız var. Bu tasarımınıza bağlı. Önceden tanımlanmış olan "rightBarButtonItem" veya "leftBarButtonItem" öğelerini Arabirim Oluşturucusu'na atama veya özel bir "IBOutlet" – vadian

+0

oluşturabilirim. Özel bir IBOutlet (IBOutlet zayıf var editBarButton) oluşturdum, ancak bunu yönteme nasıl yazacağımı bilmiyorum. .. İlk başlık 'Bitti' ve ikincisi 'Düzenle' olmak isterim. – Laroms

İlgili konular