TableViewController's viewDidLoad not firing

南楼画角 提交于 2019-12-04 07:39:05

There are multiple issues with TableViewController (as per the project archive you shared)

TableViewController.h

@interface TableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, HomeModelProtocol>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
@property (weak, nonatomic) IBOutlet UITableView *listTableView;
@end

should be:

//subclass should be UITableViewController
@interface TableViewController : UITableViewController <HomeModelProtocol>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
//not needed
//@property (weak, nonatomic) IBOutlet UITableView *listTableView;
@end

TableViewController.m

in -viewDidLoad, observe:

-(void)viewDidLoad
{
    //...

    //crashes when adding gesture to a tableView (this is not part of the core problem
    //but will be one if not handled) for now... comment it
    //[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

    //not needed as it's done via IB (but this is not part of the problem)
    //self.listTableView.delegate = self;
    //self.listTableView.dataSource = self;

    //...
}

Storyboard

Select that UITableViewController:

  • Specify custom class as TableViewController (via Identity Inspector)
  • Set Top Bar to Translucent Navigation Bar (via Attributes Inspector)
  • Add a UINavigationItem
  • Add a UIBarButtonItem on it and set it to menu (as you've done in the other viewControllers)
    • Connect the IBOutlet object sidebarButton to this UIBarButtonItem

SidebarViewController.m

in your -prepareForSegue:sender: method, if you aren't passing data to TableViewController then you need not do anything

- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
    //...

    if ([segue.identifier isEqualToString:@"showList"]) {
        //TableViewController *tableController = (TableViewController*)segue.destinationViewController;

        //this is definitely not needed whether you pass data or not
        //[tableController view];
    }

    //...
}

Move your code to

- (void)viewDidAppear:(BOOL)animated

hope it will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!