Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen "programmatically" creating UINavigationController and UITabBarController, how do I address their functions (like viewWillAppear?)
    primarykey
    data
    text
    <p>I am creating my Nav and TabBar in code at launch via: IN : myAppDelegate.m</p> <pre><code>- (void)applicationDidFinishLaunching:(UIApplication *)application { // set up a local nav controller which we will reuse for each view controller UINavigationController *localNavigationController; // create tab bar controller and array to hold the view controllers tabBarController = [[UITabBarController alloc] init]; NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4]; // setup the first view controller (Root view controller) RootViewController *myViewController; myViewController = [[RootViewController alloc] initWithTabBar]; // create the nav controller and add the root view controller as its first view localNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController]; // add the new nav controller (with the root view controller inside it) // to the array of controllers [localControllersArray addObject:localNavigationController]; // release since we are done with this for now [localNavigationController release]; [myViewController release]; // setup the first view controller just like the first ResortsListViewController *resortsListViewController; resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil]; resortsListViewController.title = @"Category1"; resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image1.png"]; resortsListViewController.navigationItem.title=@"Category1"; localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController]; [localControllersArray addObject:localNavigationController]; [localNavigationController release]; // setup the second view controller just like the first ResortsListViewController *resortsListViewController; resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil]; resortsListViewController.title = @"Category2"; resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image2.png"]; resortsListViewController.navigationItem.title=@"Category2"; localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController]; [localControllersArray addObject:localNavigationController]; [localNavigationController release]; // setup the third view controller just like the first ResortsListViewController *resortsListViewController; resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil]; resortsListViewController.title = @"Category3"; resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image3.png"]; resortsListViewController.navigationItem.title=@"Category3"; localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController]; [localControllersArray addObject:localNavigationController]; [localNavigationController release]; [resortsListViewController release]; // load up our tab bar controller with the view controllers tabBarController.viewControllers = localControllersArray; // release the array because the tab bar controller now has it [localControllersArray release]; // add the tabBarController as a subview in the window [window addSubview:tabBarController.view]; // need this last line to display the window (and tab bar controller) [window makeKeyAndVisible]; } </code></pre> <p>As you see, I am re-using ResortsListViewController for different category displays (resorts with Beaches, resorts with Pools, resorts with espresso bars) ... now, without harassing me (grin) about the silliness of my categories (cos this is a test app) I need need to do several things:</p> <ol> <li><p>I need to be able to know which tab click caused the ResortsListViewController to be displayed. I was hoping to use TAG but "initWithRootViewController" does not have the "tag" control. So, if i use an imagefilename that is the category name, I can use that filename to distinguish categories...or even navigationItem name. I need to know if there is a way for ResortsListViewController to know which tabbar item click caused it's display. I thought to look for a "action" that I could assign to the tabbar item, but that is not the way tabbarcontroller works. </p></li> <li><p>When clicking from one tab to another, the view does indeed change, the title of ResortsListViewController changes, etc...but the TABLEVIEW it holds does not clear and display any new data. Searching the web I have found a possible solution: </p></li> </ol> <p><a href="http://discussions.apple.com/thread.jspa?threadID=1529769&amp;tstart=0" rel="nofollow noreferrer">http://discussions.apple.com/thread.jspa?threadID=1529769&amp;tstart=0</a></p> <p>basically saying:</p> <blockquote> <p>In order for UINavigationControllers to send "viewWill/Did/Appear/Disappear" messages, it needs to have received "viewWill/Did/Appear/Disappear" from its container.</p> </blockquote> <p>What is the container for my UINavigationControllers in this situation? myAppDelegate is defined in the .h file as:</p> <pre><code>NSObject &lt;UIApplicationDelegate, CLLocationManagerDelegate&gt; </code></pre> <p>and does not have a:</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { } </code></pre> <p>section. When I add one it says "NSObject may not respond to -viewWillAppear" in the debugger.</p> <p>Any help out there?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload