How to Expand UITableView Delete

Asked 2 years ago, Updated 2 years ago, 40 views

Create a MyTableView that inherits UITableView

UUITableView#delegate:UITableViewDelegate 「 is UUIScrollView#delegate:
I'd like to expand to MyTableView#delegate:MyTableViewDelegate

However, if you write normally, the error will be as follows:

class MyTableView:UITableView{
    override vardelegate: MyTableViewDelegate?//Property 'delegate' with type 'MyTableViewDelegate?'cannot override a property with type 'UITableViewDelegate?'
}

protocolMyTableViewDelegate:UITableViewDelegate{
}

What should I do?

swift ios

2022-09-30 19:32

1 Answers

I think it's better to name a different variable and substitute it for the original delivery.

class MyTableView:UITableView{
    varmyDelegate:MyTableViewDelegate?{
        set(value){
            self.delegate=value
        }
        get{
            return self.delegate as ?MyTableViewDelegate
        }
    }
}

By the way, I do not recommend inheriting UITableView unless you are very particular about UI.


2022-09-30 19:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.