views:

319

answers:

2

I am trying without success to load PatientListTableViewController from a button on my first page. I have a tab bar item to get to this page already. However I want this same page accessed from a button on my start page because PatientListTableViewController is a tab item that is not seen on the tab bar when the user first opens the page. How would I code this?

The header file of PatientListTableViewController includes:

@interface PatientListTableViewController : UITableViewController <PatientAddDelegate, NSFetchedResultsControllerDelegate, UINavigationBarDelegate, UITabBarControllerDelegate>{

Thanks in advance for any help

The header file of PatientListTableViewController includes:

@interface PatientListTableViewController : UITableViewController [PatientAddDelegate, NSFetchedResultsControllerDelegate, UINavigationBarDelegate, UITabBarControllerDelegate] {
A: 

If you are already setting this view controller as a sub-view-controller of your UITabBarController, I'd use either setSelectedIndex: or setSelectedViewController on the UITabBarController. If you don't do it this way, you're going to have issues because you may have loaded that view controller's view in two different places (under the tab bar, and wherever you're placing it when you load it manually).

Here's some sample code. I'm assuming that your application delegate has an instance variables myTabBarController, and that you're putting two view controllers in the UITabBarController: myFirstViewController and mySecondViewController. I'll assume that you've set both of these view controllers as children of the tab bar controller in your NIB file.

- (void)buttonPressed:(id)sender {
    [myTabBarController setSelectedViewController:mySecondViewController];
    // Alternately, you could set the index rather than the actual VC:
    // [myTabBarController setSelectedIndex:1]
}

If your issue is related to loading a view controller without a NIB file, make sure you're setting up your view hierarchy correctly in that view controller's loadView method.

pix0r
OK you totally lost me and that is probably because I am new to coding. This controller is a subview of my UITabBarController. The setSelectedViewController sounds like the way I need to go however how do I implement this? Can you provide sample code to invoke the button to load this ViewController
SympleMyne
Solution above did not work for me after implementing this code into myFirstViewController:#import "MyFirstViewController.h"#import "MyAppDelegate.h"@implementation MyFirstViewController@synthesize tabBarController;- (void)buttonPressed:(id)sender {[tabBarController setSelectedViewController:patientListController]In my MyAppDelegate.h file I have:IBOutlet UITabBarController *tabBarController; IBOutlet MyTableViewController *patientListController;In my MyAppDelegate.m file I have:@implementation MyAppDelegate @synthesize patientListController;@synthesize tabBarController;
SympleMyne
SympleMyne, would you mind editing your original post with this additional code? It's difficult to read in a comment as there is no formatting.
pix0r
A: 

Solution above did not work for me after implementing this code into myFirstViewController:

import "MyFirstViewController.h"

import "MyAppDelegate.h"

@implementation MyFirstViewController

@synthesize tabBarController;

  • (void)buttonPressed:(id)sender { [tabBarController setSelectedViewController:patientListController]

In my MyAppDelegate.h file I have:

IBOutlet UITabBarController *tabBarController; IBOutlet MyTableViewController *patientListController; .... end

In my MyAppDelegate.m file I have:

@implementation MyAppDelegate @synthesize patientListController;

@synthesize tabBarController; ... end

Did I miss something here?

SympleMyne