iPhone ModalViewController from First Tab Bar View - uitabbarcontroller

I am trying to launch an initial login/registration screen before my TabBarController View loads. I have read that putting a ModalViewController in the First View is a good way to go. This works, but I am trying to add navigation controls to the ModalViewController. I am getting the following issues:
1 - ERROR: Property 'navigationController' not found on object of type 'AppDelegate'
2 - WARNING: Initializing 'AppDelegate *'with an expression of incompatible type 'id'
here is the code on my ModalViewController:
-(IBAction)signUpButtonTapped {
// i need to get the control for main navigation controller
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[appDelegate.navigationController popToRootViewControllerAnimated:NO];
// create object from app main view to push it
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:#"SignUpViewController" bundle:nil];
[AppDelegate.navigationController pushViewController:signUpViewController animated:YES]; }
Anyone have any ideas? Thanks so much!

There are Two Problems in your code
1) Accessing the OBJECT with class name. It must be appDelegate.nav... (small a for Solving 1 ERROR)
[appDelegate.navigationController pushViewController:signUpViewController animated:YES];
2) Type Casting the assignment (for Solving 2 Warning)
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
So your Complete working Code must go as
-(IBAction)signUpButtonTapped {
// i need to get the control for main navigation controller
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate.navigationController popToRootViewControllerAnimated:NO];
// create object from app main view to push it
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:#"SignUpViewController" bundle:nil];
[appDelegate.navigationController pushViewController:signUpViewController animated:YES];
}

AppDelegate instance declaration is like this:
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
Change this and u r good to go.

In your Code Modify this Line
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
as
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
and try now

1.make sure your appDelegate have a UINavigationController property called navigationController.
2.Line 2 of your code:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
3.last line of your code:
[appDelegate.navigat.... NOT:[AppDelegate.navigatio....

Related

How to create Side Menu on right side in Swift 3.0?

I am a beginner and I wanted to create a side menu on the right side.
So far I have a UIButton on right top side of viewController, what I want is when I click that button I want to show/hide slide menu with say 3 items…
when I click each item it will go to the different view controller. In my project, i am showing slide menu in only one viewController using AMSlideMenu. Thanks in advance.
Anuj just follow the steps-
Create a SideMenuViewController which is sub class of UIViewController , using storyboard how it will look according to the requirement.
Add this SideMenuViewController and its view as a child view controller in parent view controller by UIButton click.
When you done, remove SideMenuViewController from parent View controller and remove its view from parent view.
Repeat 2 and 3 for all view controllers.
Updated code :
Declare in your view controller -
var sideMenuViewController = SideMenuViewController()
var isMenuOpened:Bool = false
In viewDidLoad
sideMenuViewController = storyboard!.instantiateViewController(withIdentifier: "SideMenuViewController") as! SideMenuViewController
sideMenuViewController.view.frame = UIScreen.main.bounds
In your button Clicked event -
func openAndCloseMenu(){
if(isMenuOpened){
isMenuOpened = false
sideMenuViewController.willMove(toParentViewController: nil)
sideMenuViewController.view.removeFromSuperview()
sideMenuViewController.removeFromParentViewController()
}
else{
isMenuOpened = true
self.addChildViewController(sideMenuViewController)
self.view.addSubview(sideMenuViewController.view)
sideMenuViewController.didMove(toParentViewController: self)
}
}
For Animation:
let transition = CATransition()
let withDuration = 0.5
transition.duration = withDuration
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
sideMenuViewController.view.layer.add(transition, forKey: kCATransition)
There is no built-in control in iOS for side-menu. However, you could use different open source libraries to achieve your goal.
Have a look at the following libraries:
https://github.com/John-Lluch/SWRevealViewController
The detailed tutorial for this library:
http://www.appcoda.com/ios-programming-sidebar-navigation-menu/
http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path

ViewDidLoad Not Called in UITabBar application

I am using Tabbar view controller as parent view controller. I am adding it from interface builder as shown in the below screen shot. Everything is working fine but the viewdidload,viewwillappear and viewdidappear methods are not calling from the begining. even if the viewcontroller is loading for the first time also. can any one please help me out code in my app delegate is
ScreenShot of IB: http://i58.tinypic.com/u4o6w.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.backgroundColor = [UIColor whiteColor];
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.window.rootViewController = self.tabBarController;
//[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
I am able to see the loaded views but the methods are not calling.
Can any one please help me out

How can I trigger one UIViewController of the UITabBarController from another UIViewController?

I have a project that is a "tab-bar controller" app. The first button is essentially a Home screen. The second one displays a UITableView of content. The third button displays a different UITableView, etc.
From the first view (Home), I have a button on the page that is functionally equivalent to the second-button of the tab controller. It is an alternative path to get to that UITableView. I do not want to send a button press to the AppDelegate's UITabBarController.
The code in HomeViewController that I want is essentially this:
-(IBAction) touchInsideButton:(id)sender {
[self presentModalViewController: [appDelegate secondViewController] animated:YES];
}
or
-(IBAction) touchInsideButton:(id)sender {
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
[appDelegate launchSecondViewController: self];
}
where, "launchSecondViewController" is (uncomment-out one of the two lines)
-(void) launchSecondViewController: (id) sender {
// [self.tabBarController presentModalViewController: secondViewController animated:YES];
// [self.tabBarController.navigationController pushViewController: secondViewController animated:YES];
}
Regardless, all three approaches give the same error:
2013-05-16 12:04:26.977 MyApp[55273:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .'
* First throw call stack:
The problem is that this instance of the second view controller, which you refer to as secondViewController, is already in the interface, as a child of the tab view controller. You cannot have it be there and also present or push it.
The way to manipulate a tab bar controller in code is to set is selectedViewController (or selected index). Try doing that instead.

How to jump to tabbarcontroller from uiviewcontroller?

I have a ViewController as initial view controller and TabbarController. There are 3 buttons on view controller and TabbarController has 3 Tabs.
I would like tapping the first button jump to first tab, second button - to the second Tab etc.
How should I do that? I'm working with storyboard
Please Clarify your question if you just want to move your tab with click on button the use selectedatindex method for tab bar.
try this,
step 1 ->import appDelegate class in your ViewController.m
#import "AppDelegate.h"
- (IBAction) BtnOneClicked: (id) sender
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.tabBarController setSelectedIndex:0];
}
- (IBAction) BtnTwoClicked: (id) sender
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.tabBarController setSelectedIndex:1];
}
- (IBAction) BtnThreeClicked: (id) sender
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.tabBarController setSelectedIndex:2];
}
A normal View Controller Button Click Event We can jump On Tab bar Controller as simple as Normal just Crete a cocoatouch class which will we sub class of UitabBarController and present to the View.
#IBAction func goActivityView(_ sender: Any) {
let gotoActivityView = storyboard?.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
self.present(gotoActivityView, animated: false, completion: nil)
}

how to create menu on any other View in cocos2D

how to create menu on any other View it mean's i m created a UIView and i want to add MenuButton on it. This is my code but it is not working properly.. The UIView is hides the MuneButton..
UIView *aview;
aview = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 300,250)];
aview.backgroundColor= [UIColor redColor];
[[[CCDirector sharedDirector] openGLView] addSubview:aview];
// Standard method to create a button
CCMenuItem *menuItem1 = [CCMenuItemImage
itemFromNormalImage:#"Icon.png" selectedImage:#"Icon.png"
target:self selector:#selector(NextButton:)];
menuItem1.position = ccp(100, 60);
CCMenu *starMenu = [CCMenu menuWithItems:menuItem1, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
and
(void) NextButton: (CCMenuItem *) menuItem
{
NSLog(#"Button1");
}
how to add Menu on UIView. I Try with AddSubview removing addChild. And i try aview removing self..
Hope it help to you..
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
When you add a subview to a UIView, you are essentially adding them on top of the view. The cocos layer is always at the bottom. You can add the view to the root view controller, but you'll take a performance hit.
You're going about this in the wrong way anyway. Put your button in a CCLayer subclass with a CCColorLayer background and add that to your running scene. In your case: self.
My Learn Cocos2D book (2nd Edition) has a chapter about UIKit integration that explains how you can place UIKit views in front of and behind the Cocos2D GL view while allowing all views (front views, cocos2d view, back views) to respond to touch events.