Swift UITableView Multi Selection Problem

2

I have a tableView that when 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 items are left without "Line Divide", and the ones below are usually selected as shown in the following print:

What can it be? Is there an XCode bug or is there any implementation that fixes this?

When I scroll down the top of the tableview, the division border also pops up.

    
asked by anonymous 31.07.2015 / 20:28

2 answers

1

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

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

If you are on iOS 7, you can reset the tab style of the table view

Using the delegate methods of table you redefine the style of the banknotes.

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 in viewDidLoad .

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

More drastic solution if none of these works

You can add a% color of% gray with height of UIView to the bottom of the ballot and remove the style of the separator, setting the style to 1 . But it would not be the 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 it:

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

In the None method:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomClassCell
     .
     .
     .
     return cell
}
    
07.08.2015 / 20:02
0

I've never worked with custom notes, but let's see what I have to try to help. Make sure that your tableView has attributes of the banknote separator in the default

.

AlsomakesureyouhavethesameattributeonyourID

AndfinallymakesureyoudonothavemorethanoneballotintableViewcontainingdifferentattributes.

    
05.08.2015 / 20:43