call method of different view controller in app delegate while a pushing new controller - ios

I am working on a chat application and on successful login I want to push view a controller and show tab bar to user.
following is the code I have used for it
This is my TabBarViewCtr
appdel=(TabBarAppDelegate *)[[UIApplication sharedApplication]delegate];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
nextFirstViewCtr = [[FirstViewCtr alloc] initWithNibName:#"FirstViewCtr" bundle:nil];
nextSecondViewCtr=[[SecondViewCtr alloc] initWithNibName:#"SecondViewCtr" bundle:nil];
nextThirdViewCtr=[[ThirdViewCtr alloc] initWithNibName:#"ThirdViewCtr" bundle:nil];
nextForthViewCtr=[[ForthViewCtr alloc] initWithNibName:#"ForthViewCtr" bundle:nil];
nextsixviewctr=[[sixviewctr alloc] initWithNibName:#"sixviewctr" bundle:nil];
}
else
{
nextFirstViewCtr = [[FirstViewCtr alloc] initWithNibName:#"FirstViewCtr-iPad" bundle:nil];
nextSecondViewCtr=[[SecondViewCtr alloc] initWithNibName:#"SecondViewCtr-iPad" bundle:nil];
nextThirdViewCtr=[[ThirdViewCtr alloc] initWithNibName:#"ThirdViewCtr-iPad" bundle:nil];
nextForthViewCtr=[[ForthViewCtr alloc] initWithNibName:#"ForthViewCtr-iPad" bundle:nil];
nextsixviewctr=[[sixviewctr alloc] initWithNibName:#"sixviewctr-iPad" bundle:nil];
}
[nextFirstViewCtr setTitle:#"1st tab"];
[nextSecondViewCtr setTitle:#"2nd tab"];
[nextThirdViewCtr setTitle:#"3rd tab"];
[nextForthViewCtr setTitle:#"4th tab"];
[nextsixviewctr setTitle:#"5th tab"];
nav1 = [[UINavigationController alloc] initWithRootViewController:nextFirstViewCtr];
nav2 = [[UINavigationController alloc] initWithRootViewController:nextSecondViewCtr];
nav3 = [[UINavigationController alloc] initWithRootViewController:nextThirdViewCtr];
nav4 = [[UINavigationController alloc] initWithRootViewController:nextForthViewCtr];
nav5 = [[UINavigationController alloc] initWithRootViewController:nextsixviewctr];
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
nav3.navigationBarHidden=YES;
nav4.navigationBarHidden=YES;
nav5.navigationBarHidden=YES;
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate = self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view];
In the login view controller i have called connect method which is in app del and this works fine, on call of the connect method and for correct credential the method which is in app del for authentication get called.
The authentication method is as follows it is in TabBarAppDelegate.
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
DDLogVerbose(#"%#: %#", THIS_FILE, THIS_METHOD);
[self goOnline];
LoginPassViewController *obj_login = [[LoginPassViewController alloc] init];
[obj_login nextOne];
}
The nexone method looks like following which is in the loginpassviewcnt. It also get called but view is not pushed.
this method is in LoginPassViewController and get called from TabBarAppDelegate
-(void)nextOne{
TabBarViewCtr *MainTab;
if(MainTab==nil){
MainTab=[[TabBarViewCtr alloc] initWithNibName:#"TabBarViewCtr" bundle:nil];
}
[self.navigationController pushViewController:MainTab animated:YES];
}
When the nextOne method is called form LoginPassViewController it does works as required, but not when it called from TabBarAppDelegate .
I am not getting any error or even application is also not crashing can anyone please let me know how to do this.
Thanks in advance.

Related

iOS 9.0 Tabbar hide automatically and viewcontroller disappear in push

I have a TabBarController with 4 Tab. When i push a ViewController from a tab then the tab is hidden automatically and its showing nothing in View. But ViewController contains a tableview with data. I have implemented tableview delegate also.I am not getting tableview delegate logs.
in appdelegate didFinishLaunchingWithOptions()
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.homeScreen = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.rootNav = [[UINavigationController alloc]initWithRootViewController:self.homeScreen];
self.window.rootViewController = self.rootNav;
[self.window makeKeyAndVisible];
Load TabBar here:
myAppDelegate.myTabBarController.selectedIndex = 0;
myAppDelegate.myTabBarController.tabBar.translucent = NO;
myAppDelegate.myTabBarController.tabBar.opaque = YES;
location_select *tab1 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:#"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab2.title = #"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:#"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:#"Deal_ViewController" bundle:nil];
tab3.title = #"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:#"Deals.png"];
MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
tab4.title = #"More";
tab4.tabBarItem.image = [UIImage imageNamed:#"More.png"];
myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,tab3,tab4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];
From Tab 4, i push Profile_ViewController:
Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:#"Profile_ViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vc animated:YES];
And already i applied there:
myAppDelegate.myTabBarController.hidesBottomBarWhenPushed=NO;
and
[self.tabBarController setHidesBottomBarWhenPushed:NO];
in viewWillAppear of Profile_ViewController. Nothings works. I just see a blank white screen.
location_select *tab1 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:#"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:#"location_select" bundle:nil];
tab2.title = #"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:#"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:#"Deal_ViewController" bundle:nil];
tab3.title = #"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:#"Deals.png"];
MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:#"MoreViewController" bundle:nil];
tab4.title = #"More";
tab4.tabBarItem.image = [UIImage imageNamed:#"More.png"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tab1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tab2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:tab3];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:tab4];
myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];
and then later on to push your vc to tab 4 you should do
Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:#"Profile_ViewController" bundle:[NSBundle mainBundle]];
[nav4 pushViewController:vc animated:YES];
here is the Solution related to your query which might help you
You might have kept your architecture as follows
Navigation Controller ---> Tab bar Controller --> 4 child View Controllers
You need to do this
Tab bar Controller --> 4 Child controllers(Each of these 4 child View Controller having its own Navigation Controller).

How to remove SWRevealViewController?

I am using SWRevealViewController in my iPhone app.
After successful login I am creating SWRevealViewController from my viewcontroller.
profileView *frontViewController = [[profileView alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
frontViewController.user_id = [defaults objectForKey:#"userid"];
appDelegate.user_id = [defaults objectForKey:#"userid"];
[self.navigationController pushViewController:revealController animated:YES];
Now I want to logout and come back to viewcontroller. I tried poptoRootviewcontroller, but not working. How to do this ?
Try this - Call from your front/rear viewController:
[self.revealViewController.navigationController popViewControllerAnimated:YES];
Try this code on your action:
ViewController *vc = [[ViewController alloc]init];
UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];
[reveal pushFrontViewController:nvc animated:YES];

How to deal with a presentModal inside a tabBar that needs to use navigationController

I'm trying to push a view controller inside a presentmodal but nothing happening. So, I have a loginController as rootViewController that push a tabBarControler then inside one of tabBar views I open a presentModal. In the presentModal I have an UITableView when clicked push another view but when I try do this nothing happen. To try be more clear here's the hierarchy:
LoginViewController(as root view controller) >>>push>>> UITabBarController(HomeViewController and two others) >>>open>>> PackViewController(presentModal) that needs to open another view by pushViewController:
The code:
AppDelegate.m
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LoginViewController_iPhone *loginViewController = [[LoginViewController_iPhone alloc] init];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:loginViewController] autorelease];
self.window.rootViewController = self.navigationController;
LoginViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
HomeViewController_iPhone *referenciaHomeViewController = [[HomeViewController_iPhone alloc] init];
MapaViewController_iPhone *referenciaMapaViewController = [[MapaViewController_iPhone alloc] init];
GuiaViewController_iPhone *referenciaMidiaViewController = [[GuiaViewController_iPhone alloc] init];
UINavigationController *navHome = [[UINavigationController alloc] initWithRootViewController:referenciaHomeViewController];
UINavigationController *navMapa = [[UINavigationController alloc] initWithRootViewController:referenciaMapaViewController];
UINavigationController *navGuia = [[UINavigationController alloc] initWithRootViewController:referenciaMidiaViewController];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tabBarBackground"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"tabBarSelected"]];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navHome, navMapa, navGuia, nil];
}
- (void)login {
[self.navigationController pushViewController:self.tabBarController animated:YES];
}
PackViewController.m (PRESENTMODAL):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
CompraPackViewController_iPhone *controller = [[CompraPackViewController_iPhone alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
When you do your present modal, you need to present a navigation controller whose root view controller is the table view controller.

How to Show LoginViewController over SplitViewController?

I am working on application for iPad which have CustomTabBar (3 Tabs), Navigation Bar and SplitView Controller.
Follow of application screens:
1-Login Screen (Present over SplitView) >> Forgot password (Push on login navigation)
2- Forget password if pushed on login navigation then it will be poped and then login will be dismissed on successful login.
3- On Successful Login, SplitView is shown.
How I code in AppDelegate:
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.detailViewController] autorelease];
customTabBarCont = [[CustomTabBarController alloc] init];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = self.detailViewController;
NSArray *viewControllers = [[[NSArray alloc] initWithObjects:customTabBarCont,detailNavigationController, nil] autorelease];
self.splitViewController.viewControllers = viewControllers;
self.detailViewController.splitViewController = self.splitViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:loginVC] autorelease];
[self.splitViewController presentViewController:loginNavigationController animated:NO completion:nil];
I have SettingViewController in which i have given the functionality of Sign-out.
It create issues when user Signout from Portrait and Login in LandscapeView
How i code for SignOut
self.loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
if ([app_delegate.detailViewController.masterPopoverController isPopoverVisible]) {
[app_delegate.detailViewController.masterPopoverController dismissPopoverAnimated:NO];
}
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.loginVC] autorelease];
When we rotate again then everything goes well. but how to solve this issue. or where i am wrong.
You just have to add one method in your DetailViewController.m
- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return NO;
}
The run you project and see what happens. Surly this will solve your problem

The correct way of adding a UINavigationController to a existing UIViewController

I'm trying to add a UINavigationController to my existing view controller by adding this in ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
navController = [[UINavigationController alloc]init];
[self.view addSubview:navController.view];
}
But by doing it this way, it completely blocks my view. It puts a UINavigationBar on the top but the rest of the view doesn't respond to input.
This is how I am presenting the view. The SecondViewController is the one I want to have a NavController:
UITabBarController *tabController = [[UITabBarController alloc] init];
FirstViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"CardsViewController" bundle:nil];
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"First"
image:[UIImage imageNamed:#"img1.png"] tag:1];
[viewController1 setTabBarItem:tab1];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"ShoppingViewController" bundle:nil];
UINavigationController *SecondViewNavCont = [[UINavigationController alloc]initWithRootViewController:viewController2];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:#"Second"
image:[UIImage imageNamed:#"img2.png"] tag:2];
[SecondViewNavCont setTabBarItem:tab2];
UIViewController *viewController3 = [[UIViewController alloc] init];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:#"Third"
image:[UIImage imageNamed:#"img3.png"] tag:3];
[viewController3 setTabBarItem:tab3];
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
nil];
[self.view addSubview:tabController.view];
You cannot add it to the current view controller
What you need to do is instead of presenting the ViewController is to add this viewcontroller to the navigationview controller and present that
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:YourPresentedViewController];
//then present the navController
[self presentModalViewController:navController animated:YES];
Now when you present it do the following
NSArray arrayWithObjects:viewController1,
SecondViewNavCont,
viewController3,
nil];
You can try this code for load uiviewcontroller to uinavigationcontroller:
yourviewController *viewcontroller=[[yourviewController alloc] initWithNibName:#"yourviewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewcontroller];
[self presentModalViewController:navController animated:YES];
(or) you want to load uinavigationcontroller in application startup try below code in your application delegate class:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewcontroller.view];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
Welcome!
You need to set the RootViewController for the navController object. Then further you can push UIViewcontroller objects using pushViewController method.
You need to add a view for that Navigation Controller. The added Navigation Controller has no view so it was overlaying on the UIViewController
You need to add
[[UINavigationController alloc] initWithNibName:#"ViewControllerName" bundle:nil];

Resources