Swift Multi Selection Problem Uitableview

Asked

Viewed 371 times

2

I have a tableView that when it is in "Edit" mode I can select each item and take an action, for example remove the selected items.

When I select the items, the first ones are left without "Line division", and the lower ones are selected normally as shown in the following print:

Os três primeiros ficaram sem borda de divisão

What can it be? An Xcode bug or is there an implementation that fixes it?

When I scroll down the top ones also disappear the dividing edge of the tableView.

  • Hello Leonardo, could you give some more information as code of the creation of the tableView and the part that you select cells? I had a similar problem only it was only in the first cell, who knows is the same mistake I was making. Thank you :)

2 answers

1

Does this problem occur on iOS 7 or iOS 8? Or both?

To UITableView in iOS uses a concept of "recycling" the ballots. Every time you use the scroll of table view it recharges the ballots. You can solve this problem in a few different ways.

If it’s iOS 7, you can reset the style of the tab table view

Using the methods delegate of table you reset the style of the ballots.

func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) {
        // Redefinindo o estilo do separador
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
        tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
}

func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) {
        // Redefinindo o estilo do separador
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
        tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
    }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        // Redefinindo o estilo do separador
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
        tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        // Por garantia também redefine o estilo do separador ao selecionar a cédula
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None;
        tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine;
 }

If you use customized ballots

You have to register the ballot on viewDidLoad.

self.tableView.registerClass(CustomClassCell.classForCoder(), forCellReuseIdentifier: "Cell")

More drastic solution if none of these works

You can add a UIView gray color with height of 1 at the bottom of the ballot and remove the style of the separator by setting the style to None. But it wouldn’t be best practice.

EDIT

Solution with ballots loaded from a nib

To create the ballot from a Nib, in viewDidLoad you must register the identifier of the same:

override func viewDidLoad() {
     super.viewDidLoad()
     self.tableView.registerNib(UINib(nibName: "CellNibName", bundle: nil), forCellReuseIdentifier: "Cell")
}

In the method cellForRowAtIndexPath:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomClassCell
     .
     .
     .
     return cell
}
  • It didn’t work because I am implementing in iOS version 8 and my "Banknote" is registered as Uinib. Let xib = Uinib(nibName: "Minhacell", Bundle: nil)

  • @Leonardorocha in viewDidLoad register your nib self.tableView.registerNib(UINib(nibName: "CellNibName", bundle: nil), forCellReuseIdentifier: "Cell"). If it still doesn’t work, give more details about creating your Tableview and ballots

  • @Leonardorocha added the code snippet for the creation and registration of Cell from a Nib

0

I’ve never worked with custom ballots, but let’s see what I can do to help. Make sure your tableView features Note Separator attributes in the default

Atributos.

Also ensure the same attribute on the ballot itself

cédula

And lastly make sure you don’t have more than one ballot on the tableView containing different attributes.

Table View Cells

  • I checked and my tableView and Cell. are exact so.

  • But the bug perssiste.

  • You have more than one ballot in Table View itself?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.