Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section custom header with xib file+class #2237

Open
DigitalVanilla opened this issue Dec 13, 2022 · 10 comments
Open

Section custom header with xib file+class #2237

DigitalVanilla opened this issue Dec 13, 2022 · 10 comments

Comments

@DigitalVanilla
Copy link

Describe the bug
I wish to re-use a custom class with a xib file in a section with some rows added dynamically,
but when I use the following code

var section = Section() { section in
      section.tag = v
      var header = HeaderFooterView<EKHeaderClass>(.nibFile(name: "EKHeader", bundle: nil))
      header.height = { 25 }
      header.onSetupView = { view, _ in
        view.titleLabel.text = "My title"
        view.subTitleLabel.isHidden = "My subtitle"
      }
     section.header = header
}

section.insert(contentsOf: [rowA, rowB], at: 0)
form.insert(section, at: mealParts.count)

I see that the xib view and its class gets instantiated but it disappear immediately;
if I keep adding more of the same to have a very long table/form and i start to scroll,
the headers reappear without problems.
On the contrary, if I use a simple view class, I have no problems and I see the header being attach
and never disappear.
Does anyone knows how to fix this?

Thanks 1k

Versions (please complete the following information):

  • Device: iPhone 12
  • OS: 15.0
  • Eureka Version 5.4.0
  • Xcode version 14.1
@DigitalVanilla
Copy link
Author

A note: if I extend a UITableViewCell, the problem occur and scrolling seems to fix this, but if I extend a UIView the problem does not appear, so something is in the UITableViewCell class extension that interfere the first time the section is attach.

@mats-claassen
Copy link
Member

So you mean this only appears when you subclass UITableViewCell? Are you doing that with your header view class (aka EKHeaderClass)? That should not subclass from UITableViewCell. Subclassing from UIView is correct

@DigitalVanilla
Copy link
Author

So you mean this only appears when you subclass UITableViewCell?
Yes I wanted to reuse a row class

Are you doing that with your header view class (aka EKHeaderClass)
Yes

Subclassing from UIView is correct
But the cell is visible initially and I see that it disappear when the row animation ends, and why scrolling shows it back?
Can I load a xib file and then assign the .contentview to the section.header? I wish to be clever and reuse the rows we have created for both rows and headers, in this way we have less classes to maintain.

@mats-claassen
Copy link
Member

Have you tried using UITableViewCell subclasses as headers of a UITableView without Eureka? I wouldn't be surprised if there is some added logic in UITableViewCell that is responsible for this.

What I would do in such a case is design a UIView with common design and use that inside both a row and a header, instead of trying to use a cell as header, but maybe it works

@DigitalVanilla
Copy link
Author

Yes, I did use subclassing the headers without having problems. At the moment I cannot put more time and money on this update to use a UIView custom class inside the headers, I wanted to re-use Eureka Custom Class (not the row) to be clever and have one class that does both things (header and regular row). But the point is that the this "glitch" occur only when the section is added, but when the header is off screen and then re enter the screen scrolling back the correct Y position, the cell is visible again; many people have this problem, is possible to track it someway?

@mlorenze
Copy link
Contributor

mlorenze commented Dec 22, 2022

Describe the bug I wish to re-use a custom class with a xib file in a section with some rows added dynamically, but when I use the following code

var section = Section() { section in
      section.tag = v
      var header = HeaderFooterView<EKHeaderClass>(.nibFile(name: "EKHeader", bundle: nil))
      header.height = { 25 }
      header.onSetupView = { view, _ in
        view.titleLabel.text = "My title"
        view.subTitleLabel.isHidden = "My subtitle"
      }
     section.header = header
}

section.insert(contentsOf: [rowA, rowB], at: 0)
form.insert(section, at: mealParts.count)

I see that the xib view and its class gets instantiated but it disappear immediately; if I keep adding more of the same to have a very long table/form and i start to scroll, the headers reappear without problems. On the contrary, if I use a simple view class, I have no problems and I see the header being attach and never disappear. Does anyone knows how to fix this?

Thanks 1k

Versions (please complete the following information):

  • Device: iPhone 12
  • OS: 15.0
  • Eureka Version 5.4.0
  • Xcode version 14.1

How is the behavior in this assignment (inside the onSetupView block):
view.subTitleLabel.isHidden = "My subtitle"

@mlorenze
Copy link
Contributor

mlorenze commented Dec 22, 2022

I created this ViewController, with the custom header subclassing UITableViewCell. I could not reproduced the issue.

import UIKit
import Eureka

class ViewController: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        for _ in 0...19 {
            createSection()
        }
    }
    
    private func createSection() {
        var section =  Section() { section in
                var header = HeaderFooterView<EKHeaderClass>(.nibFile(name: "EKHeader", bundle: nil))
                header.height = { 25 }
                header.onSetupView = { view, _ in
                    view.titleLabel.text = "My title"
                }
                section.header = header
            }
        
        let rowA = LabelRow() {
            $0.title = "Row A!!!"
        }
        
        let rowB = LabelRow() {
            $0.title = "Row B!!!"
        }
        
        section.insert(contentsOf: [rowA, rowB], at: 0)
        form.insert(section, at: 0)
    }
}

class EKHeaderClass: UITableViewCell {

    @IBOutlet var titleLabel: UILabel!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}

Versions:

Device: iPhone 14 Pro
iOS: 16.1 (20B72)
Eureka Version 5.4.0
Xcode version 14.1 (14B47b)

@DigitalVanilla
Copy link
Author

How is the behavior in this assignment (inside the onSetupView block): view.subTitleLabel.isHidden = "My subtitle"
I have a stackview vertical and when there is only the title I hide the subtitle

@DigitalVanilla
Copy link
Author

DigitalVanilla commented Dec 23, 2022

Ok, so is possible to use a custom tableviewcell instead of a view, good to know.

@DigitalVanilla
Copy link
Author

Ok, I was testing it and I found out that if I delay the creation of the sections with the custom header form a nib, it does not works.
Please add this to your code:


DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
      for _ in 0...19 {
        self.createSection()
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants