UITableViewCell is repeating after every 5th cell (Before you mark as duplicate kindly read the whole quest )
Remember - the cells are being reused.
You hide the cell, but you never explicitly unhide the cell
When you come to row 6, you are re-using the cell that was at row 0, and isHidden = true
All you need to do is extend your check, and hide the rows that you need to be hidden, and explicitly show the cells that you need to see. If you also have a moving banner that you add - you will also need to check to see if it's been loaded, and remove it if not required. Remember - it may not be row 6 - that's just how it works out with the current screensize
If you do have significant differences between the cells you want to use, you might be better using two different classes - and then you don't have to think about hiding labels
class demoTableCell: DemoTableCellNormalRow {
@IBOutlet var name : UILabel!
@IBOutlet var area : UILabel!
}
class demoTableCell: DemoTableCellFirstRow {
@IBOutlet var area : UILabel!
@IBOutlet var movingBannerView : LCBannerView!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
if row == 0 {
var cell : demoTableCell = demoTable.dequeueReusableCell(withIdentifier: cellIdentifier)! as! DemoTableCellFirstRow
cell.area.text = (arrDemo.object(at: indexPath.row) as! NSDictionary).value(forKey: "Area") as? String
// populate the bannerview which already exists, or create a new one
return cell
} else {
var cell : demoTableCell = demoTable.dequeueReusableCell(withIdentifier: cellIdentifier)! as! DemoTableCellNormalRow
cell.name.text = (arrDemo.object(at: indexPath.row) as! NSDictionary).value(forKey: "Name") as? String
cell.area.text = (arrDemo.object(at: indexPath.row) as! NSDictionary).value(forKey: "Area") as? String
return cell
}
}
UITableView Custom Cell is duplicating UIButton on scroll
Because cells are reusable, content stays. So your old buttons are still in your stack view and you're adding next buttons every time.
To fix this, before you add new buttons to UIStackView
remove old buttons
extension ButtonCell {
fileprivate func anchorSubViews() {
...
for case let button as UIButton in buttonGroupStackView.subviews {
button.removeFromSuperview()
}
for (index, b) in buttons {
...
buttonGroupStackView.addArrangedSubview(btn)
}
...
}
}
tableview duplicate cell went scrolling down
..ReusableCell
means what it says: Cells are reused. All views which are added to the cell will remain.
You are responsible to keep the cell in a defined state.
I'd recommend to create a custom cell in Interface Builder with all desired UI elements and IBOutlet
s.
Related Topics
How to Find the Index of a Tuple Element from an Tuple Array? iOS, Swift
How to Use Alamofires Servertrustpolicy.Disableevaluation in Swift 3
Swift and Nsuserdefaults - Exc_Bad_Instruction When User Defaults Empty
How to Detect Which Image Has Been Tapped in Swift
How to Add Two or More Buttons to Annotationview: Mkannotationview
Show More Button Next to End of Text Swift
Get Total Include Months Between 2 Date in Swift
Wkwebview: How to Preload Multiple Urls
Custom Uibutton Class for Button Touch Event
Swift Computed Properties Cannot Be Used in Init
How to Read References Given by Ptr_Refs in iOS
iOS How to Restart App for Changing Language Swift 4
How to Remove Single Object in Array from Multiple Matching Object
Adding Firebase Data to an Array in iOS Swift
Add View as a Parameter to a Custom Viewmodifier
My Reachability Notifier Is Only Able to Be Called Once