add many view controller - objective-c

How can I receive different values from appDelegate?
#synthesize window;
#synthesize viewController;
#synthesize viewController2;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController2.view];
[self.window addSubview:viewController.view];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (choix==6) {
XMLTestAppDelegate *appDelegatess = (BroseFormular2*)[[UIApplication sharedApplication] delegate];
appDelegatess.viewController2.detailItem =[listOfMovies objectAtIndex:indexPath.row];
}
else if (choix==7)
{
XMLTestAppDelegate *appDelegate = (BroseFormular2*)[[UIApplication sharedApplication] delegate];
appDelegate.viewController2.detailItem =[listOfMovies objectAtIndex:indexPath.row];
}
else {
NSLog(#"no");
XMLTestAppDelegate *appDelegates = (authe*)[[UIApplication sharedApplication] delegate];
appDelegates.viewController.detailItem =[listOfMovies objectAtIndex:indexPath.row];
}

There should be only one view controller in the window on the iPhone. Only one controller should be controlling the view at a time.
This is going to be a problem:
[self.window addSubview:viewController2.view];
[self.window addSubview:viewController.view];
[EDIT] Actually, there are cases where you can have two view controllers active on the iPad, for example you can have a view controller in a pop up view.

Related

changing default view with master/detail application

can you help me with this one? I'm creating an app and I'm using a master/detail application, then I added a new class called MenuViewController and I want it to be the initial view to load when my app starts. I was able to do it but my MasterViewController does not work any more, everytime i click an item in the table view it's suppose to show another view called DetailViewController but ever since I changed the default view it doesn't show the DetailViewController anymore
Here's a piece of code i've done
in the appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MenuViewController *menuView = [[[MenuViewController alloc]initWithNibName:#"MenuViewController" bundle:nil]autorelease];
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
self.window.rootViewController = menuView;
[self.window makeKeyAndVisible];
return YES;
}
and in my MenuViewController.m
// Created by Jan Arman Capistrano on 2/6/13.
// Copyright (c) 2013 Jan Arman Capistrano. All rights reserved.
//
#import "MenuViewController.h"
#import "MasterViewController.h"
#interface MenuViewController ()
#end
#implementation MenuViewController
-(IBAction)nextView:(id)sender
{
MasterViewController *masterViewc = [[MasterViewController alloc]initWithNibName:nil bundle:nil];
[self presentViewController:masterViewc animated:YES completion:nil];
}
It seems your MasterViewController is instantiated from a XIB. If so, check that the UITableView has its delegate and datasource bindings (propably the MasterViewController itself)
have you tried to set a breakPoint in your - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method, to see if it's actually called ?

ViewController Delegate

is it possible to access a ViewController's methods from the appDelegate, like it is possible inverse with the following code:?
AppDelegate *ad = (AppDelegate *) [[UIApplication sharedApplication] delegate];
When I try
ViewController *vc = (ViewController *) [[UIApplication sharedApplication] delegate];
I get an error...
Thanks!
In your AppDelegate, assuming viewController is your rootViewController, you can get a list of all view controllers on the stack by with:
NSLog(#"List of current active view controllers:%#", self.viewController.navController.viewControllers);
To access a specific view controller in the viewControllers:
[[self.viewController.navController.viewControllers objectAtIndex:i] someMethodOfThatViewController];
ViewController *vc = (ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
or if your delegate have properties
YourAppDelegate *ad = (YourAppDelegate*)[UIApplication sharedApplication].delegate;
ViewController *vc = ad.yourViewControllerProperty;

ios remove tabbar on button touch

I've a tab bar based project created and added a login view prior to tab view like this.
AppDelgate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
loginView = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
loginView.delegate = self;
[window addSubview:loginView.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void) loginViewControllerDidFinish:(LoginViewController *) loginViewController{
[window addSubview:tabBarController.view];
}
I'm calling loginViewControllerDidFinish: after authentication in LoginViewController as
[self.delegate loginViewControllerDidFinish:self];
Now in one of the tabs i've added logout button and want to come back to loginView on touch.
-(IBAction) logout:(id)sender{
NMSAppDelegate *appDelegate = (NMSAppDelegate *)[[UIApplication sharedApplication] delegate];
//[appDelegate.tabBarController release];
[appDelegate.tabBarController.view removeFromSuperview];
}
it shows the loginView after calling the above method but after re-login it shows all the previous data and previously selected tab but i want it to be afresh from the first tab.Is there anyway to completely delete the tabbar on logout.so that i'm starting the new session.
Thanks
Cant you create another instance of appDelegate.tabBarController ?
Something like this:
appDelegate.tabBarController = [[UITabBarController alloc] init];
appDelegate.tabBarController.viewControllers = [NSArray arrayWithObject:VIEW_CONTROLLER1, VIEW_CONTROLLER2,nil];
appDelegate.window.rootViewController = tabBarController;
[appDelegate.window makeKeyAndVisible];

Unable to display tableView in iOS app

I am fairly new to iOS and am attempting to display a tableView controller from another tableView controller in a drill down routine for an iPad app. However, the new tableView will not display. I can follow the program logic through the following routine in debug mode but after this logic, the same view remains on the screen. I set breakpoints in the new tableview program to be displayed and they are never reached. I have included the HEDView.h in the application file for this program and have no clue why the new view is not displayed. Any help is or suggestions for more info is appreciated.
Here is the routine to call the tableView: HEDView will not display.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
[tableView deselectRowAtIndexPath:indexPath animated:NO];
HEDView *detailViewController = [[HEDView alloc] initWithNibName:#"HEDView" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.title = #"HEDView";
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
If your requirement is to navigate to other viewcontroller when cell in the row is selected, then I think your navigationcontroller is not properly allocated.While debugging check whether self.navigationController is returning proper address.If not then you have to first properly allocate it.
and one more thing, HEDView is UIViewController so you should follow proper naming convention.
Implement - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in AppDelegate.m, and also include #property (nonatomic, retain) UINavigationController *navControl; in AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:[navControl view]];
[self.window makeKeyAndVisible];
return YES;
}
I think it will be helpful to you.

How to change RootViewController (in AppDelegate) from within CustomViewController?

Good day,
My app has authorization form (SigninController) which is loaded in AppDelegate, and after signing in (checking is in SigninController.m) TabBarController should appear (as main view of application).
How can I change controller from Signin to TabBar and where ??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SigninController *aSigninController = [[SigninController alloc] initWithNibName:#"SigninView" bundle:nil];
self.currentController = aSigninController;
[aSigninController release];
self.window.rootViewController = self.currentController;
[self.window makeKeyAndVisible];
return YES;
}
SigninController.m
- (IBAction)signinClick
{
........
if (loginOK == YES)
{
//This place is ready to send messages to show TabBar
} else {
UIAlertView *alert = ......
[alert show];
[alert release];
}
}
[appDelegate.window addSubview:appDelegate.tabbarController.view];
[self.view removeFromSuperview];
appDelegate is the application shared delegate.
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];