2017-07-05 11 views
0

私はテーブルビューコントローラを持っており、左のバー編集アイテムボタンを埋め込んでいます。テーブルビューセルを削除

override func viewDidLoad() { 
     super.viewDidLoad() 
navigationItem.leftBarButtonItem = self.editButtonItem 
} 
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     return true 
    } 
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 

     if (editingStyle == UITableViewCellEditingStyle.delete) { 

      MessageTableView.deleteRows(at: [indexPath], with: .fade) 
     } 

} 

私は編集ボタンをクリックすると、円はそれにenter image description here

をチェックマークを配置するためにポップアップ表示されます。しかし、私は編集ボタンをクリックしたときに、私はenter image description here

表示される赤いマイナス記号をしたいです

しかし私が従うすべてのチュートリアルでは、私は最初の画像を取得し、私はそれを望んでいません。

+0

は、複数選択をサポートするために、あなたのテーブルビューのセットアップですか? 'allowsMultipleSelectionDuringEditing'は' true'に設定されていますか(またはInterface Builderで有効になっていますか)? – rmaddy

+0

@rmaddyはいtrueに設定されています – juelizabeth

+0

これを 'false'に設定します。 – rmaddy

答えて

2

質問の下のあなたのコメントに基づいて、テーブルビューのallowsMultipleSelectionDuringEditingプロパティを有効にしました。これを有効にすると、テーブルビューの編集中に複数の選択がサポートされます。これは、削除などの「通常の」編集機能をサポートするよりも優先されます。このため、赤い削除サークルの代わりにチェックボックス(選択用)が表示されます。

編集モードで赤丸でセルを削除する場合は、編集中に複数の選択を無効にする必要があります。

0
var arrayDays:[Student] = [] 

    @IBOutlet var tableViewForStudents: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     let std1 = Student(name: "First", rollNo: 1, address: "this is \\n address of \\n student 1",image:"demo.png") 
     let std2 = Student(name: "Two", rollNo: 2, address: "this is \\n address of \\n student 2",image:"demo.png") 
     let std3 = Student(name: "Three", rollNo: 3, address: "this is \\n address of \\n student 3",image:"demo.png") 
     let std4 = Student(name: "Four", rollNo: 4, address: "this is \\n address of \\n student 4",image:"demo.png") 
     let std5 = Student(name: "Five", rollNo: 5, address: "this is \\n address of \\n student 5",image:"demo.png") 
     let std6 = Student(name: "Six", rollNo: 6, address: "this is \\n address of \\n student 6",image:"demo.png") 

     arrayDays.append(std1) 
     arrayDays.append(std2) 
     arrayDays.append(std3) 
     arrayDays.append(std4) 
     arrayDays.append(std5) 
     arrayDays.append(std6) 

    } 
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 

     if editingStyle == .delete { 
      arrayDays.remove(at: indexPath.row) 

      tableView.deleteRows(at: [indexPath], with: .left) 
     } 

輸入のUIKit

class Student: NSObject { 

    var strStudentName:String! 
    var strStrudentRollNo:Int! 
    var strStudentAddress:String! 
    var imageName:String! 

    init(name:String, rollNo:Int, address:String,image:String) { 

     strStudentName = name 
     strStrudentRollNo = rollNo 
     strStudentAddress = address 
     imageName = image 
    } 
    } 
関連する問題