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

EmptyDataSetSource function not get called on subclass if parent class has not implement that EmptyDataSetSource function #30

Open
Oowomn opened this issue May 23, 2019 · 1 comment

Comments

@Oowomn
Copy link

Oowomn commented May 23, 2019

For example, a viewcontroller called ParentVC has implement EmptyDataSetSource with below delegate function.

func title(forEmptyDataSet _: UIScrollView) -> NSAttributedString? {
	return NSAttributedString(string: "title")
}

Now, a viewcontroller called SubVC which inherited ParentVC. if I want to show a button when tableview is empty. I added this delegate method.

func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return NSAttributedString(string: "Add")
}

The result is the subclass delegate method will not be called. There is no button shown. This is not I expected.

And I test that if I add the function above at ParentVC and override in SubVC. Then it works.

In ParentVC
func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return nil
}
In SubVC
override func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return NSAttributedString(string: "Add")
}

It is strange that I need to implement the function into ParentVC which is useless to ParentVC. If I have many different subclass of ParentVC which has their own special handling. I have to add all those method on ParentVC first and override at subclass then.

@Xiaoye220
Copy link
Owner

I think it's because I extend the EmptyDataSetSource to provide default implementations. Just like this question.

public extension EmptyDataSetSource {
    func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
        return nil
    }
}

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

2 participants