I want TableView to be in edit mode with animation without editButtonItem

Asked 2 years ago, Updated 2 years ago, 58 views

We have switched the Table view from the buttons on our own navigation bar to edit mode as shown below.However, when I used editButton, there was an animation with a red button on the left that went into edit mode, but it disappeared with this method.Is there a way to add animation?

let anotherButton: UIBarButtonItem=UIBarButtonItem(title: "Show", style: UIBarButtonItemStyle.Plain, target:self, action: "openMenu:")

    self.navigationItem.rightBarButtonItem=anotherButton;

US>funcopenMenu (sender: UIBarButtonItem) {

    self.setEditing (editing, animated:true)

    editing=!editing
}

swift uitableview

2022-09-29 22:41

2 Answers

self.setEditing (editing, animated:true)

I think this part will be in edit mode with animation using the following code

self.tableView.setEditing (banimated:true)


2022-09-29 22:41

How about preparing a flag?

 var flag = false

let anotherButton: UIBarButtonItem=UIBarButtonItem(title: "Show", style: UIBarButtonItemStyle.Plain, target:self, action: "openMenu:")

US>funcopenMenu (sender: UIBarButtonItem) {
 if flag{
  flag = false
 } else {
  flag = true
 }
 self.tableView.setEditing (flag, animated:flag)
 tableView.isEditing=flag
}


2022-09-29 22:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.