UITableView delegate and dataSource methods not getting called

后端 未结 8 1388
野性不改
野性不改 2021-02-13 14:23

I have a UIView which contains a UITableView. The tableview\'s delegate is set to my UIView, but it never calls the delegate methods:

-(id)init {
    self = [sup         


        
相关标签:
8条回答
  • 2021-02-13 15:13

    Can you please write the code that you have written on your cellForRowAtIndexPath: method? Because i can't find anything wrong with your code.

    Are you calling your UIView from some other ViewController? If yes, how?

    I have done something like this once. I declared a method in the UIView like this :

    - (void)setUpTableView{
        self.tableview.delegate=self;
        self.tableview.dataSource=self;
    }
    

    And then i called the setUpTableView from the view controller i added this view to, like this :

    [self.yourView setUpTableView]; 
    

    This might help. Thanks.

    0 讨论(0)
  • 2021-02-13 15:14

    You do not need to use a UIViewController, that's just a smokescreen. You also do not need to add to the .h, although you should do that anyway because Xcode will complain otherwise, and you won't get method name auto complete.

    I just wrote a test project that embeds a table view in a normal UIView and it works fine. Just make sure your initialization code is being called. I bet you need to move it to awakeFromNib.

    0 讨论(0)
提交回复
热议问题