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
}
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 :)
– Lucas Eduardo