TableViewController viewDidLoad not working

I followed this tutorial to have a shutdown menu. I added a TableViewController that will display a list of articles. For some reason it viewDidLoaddoesn't work.

This guide SideViewControllerwill control which controller will be displayed, if present seguewith the identifier "showPhoto" it will load a specific image.

// Set the photo if it navigates to the PhotoView
if ([segue.identifier isEqualToString:@"showPhoto"]) {
    PhotoViewController *photoController = (PhotoViewController*)segue.destinationViewController;
    NSString *photoFilename = [NSString stringWithFormat:@"%@_photo.jpg", [menuItems objectAtIndex:indexPath.row]];
    photoController.photoFilename = photoFilename;
}

I thought about recreating the same for TableViewControllerand trying to force the viewDidLoadcontroller, as shown here Force viewDidLoad to run in iOS , but it still does not work:

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

TableViewController viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Change button color
    _sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.9f];

    // Set the side bar button action. When it tapped, it'll show up the sidebar.
    _sidebarButton.target = self.revealViewController;
    _sidebarButton.action = @selector(revealToggle:);

    // Set the gesture
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

    // Set this view controller object as the delegate and data source for the table view
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;

    // Create array object and assign it to _feedItems variable
    _feedItems = [[NSArray alloc] init];

    // Create new HomeModel object and assign it to _homeModel variable
    _homeModel = [[HomeModel alloc] init];

    // Set this view controller object as the delegate for the home model object
    _homeModel.delegate = self;

    // Call the download items method of the home model object
    [_homeModel downloadItems];
}

, (PhotoViewController MapViewController) , ... , , .

iOS, , .

+4
2

TableViewController ( )

TableViewController.h

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

:

//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

-viewDidLoad, :

-(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 done via IB (but this is not part of the problem)
    //self.listTableView.delegate = self;
    //self.listTableView.dataSource = self;

    //...
}

UITableViewController:

  • TableViewController ( Identity Inspector)
  • Top Bar Translucent Navigation Bar ( )
  • UINavigationItem
  • UIBarButtonItem ( viewControllers)
    • IBOutlet sidebarButton UIBarButtonItem

SidebarViewController.m

-prepareForSegue:sender:, TableViewController,

- (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];
    }

    //...
}
+1

- (void)viewDidAppear:(BOOL)animated

, .

+1

Source: https://habr.com/ru/post/1542747/


All Articles