I want to put tabbar on second view - ios

Usally ,tabbar always displays buttom.
like this.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
but I want to diplay tabbar on second view (only).
1-2 is connected by navicontroller
2 is #interface TableViewController :UITableViewController
how??

better to add the tab bar controller programmatically in secondviewcontroller viewdidload

Related

Changing the first ViewController in iOS

Initially I developed the app with only one ViewController(called MainView). Now I'd like to add one ViewController (called LoginView)infront of MainView. I added in the AppDelegate as
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginPage *RootViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"LoginPage"];
[UIApplication sharedApplication].delegate.window.rootViewController = RootViewController;
[[UIApplication sharedApplication].delegate.window makeKeyAndVisible];
return YES;
}
It looks working, but only black screen appears.
My LoginPage ViewController has the following structure. The ViewController has two buttons, one label and one text view. They don't appear and only black screen is appearer.
Just mark your Login view controller as initial view controller in storyboard

Displaying View Controller on top of other when app starts does not work in ios8

I use following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
window.rootViewController = self.viewController;
[window makeKeyAndVisible];
if (self.requireLogin){
[self.viewController presentViewController:self.loginViewController animated:NO completion:nil];
}
}
So i push loginViewController on top of viewController. This works ok on iOS prior to 8, but on iOS 8 you can see for small amount of time the viewController.
Is there simple way to present view controller on iOS 8 without showing what is behind it ?
Edit:
Noticed in log that it has also "Unbalanced calls to begin/end appearance transitions" so think ios 8 runs some animation on self.viewController. Is there way to stop it animating ?
Try this Hide Initially, then unhide it.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
window.rootViewController = self.viewController;
// Hide initially
window.rootViewController.view.hidden = YES;
[window makeKeyAndVisible];
if (self.requireLogin){
[self.viewController presentViewController:yourloginViewController animated:NO completion:^{
// Unhide now
window.rootViewController.view.hidden = NO;
}];
}
}
Based on the response , It seems to be not showing the splash screen, So my better suggestion is
As you knew the YES/No to show the login view(based on self.requireLogin), you make login view controller as rootviewcontroller of your window.
if (self.requireLogin){
window.rootViewController = yourLoginViewController;
}
else{
window.rootViewController = normalViewController;
}
Still you need to use the same strategy of yours then add one UIImageView on the normal View Controller, then present login view controller.
The option is yours:)

viewController initial class set

I have two view controllers, a default ViewController and the one I added later for login: LoginViewController. I set LoginViewController as initial view. But when I run the app, after viewDidLoad in LoginViewController it fires -viewDidLoad in ViewController also.
I have a modal segue, after login is successful to perform segue and show me the ViewController, that works. But in execution of app ViewController is also fired. Does anyone have an idea why this happens? AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"LoginView"];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}

For iOS, Any way to know the navigation source?

Any way to know the navigation source?
For example, the navigation stack has A/B/C three view controllers.
If C is popped, when B is displayed, any way to know the navigation is from C to B ?
Thanks a lot in advance.
in another simple method
first declare the UINavigationController in Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[nav setNavigationBarHidden:YES];
[self.window makeKeyAndVisible];
return YES;
}
after that in your first view controller.m import the second view controller header file
#import "B.h"
in your button action
- (IBAction)butvie:(id)sender {
B*tab=[[Balloc]init];
[self.navigationController pushViewController:tab
animated:YES];
}
in C viewcontroller comes to back of B
- (IBAction)butvie:(id)sender {
[self.navigationController popViewController
animated:YES];
}
You can track this manually. You can keep a global variable in your AppDelegate class and set that variable whenever you pop a particular viewController.
UPDATE after comments:
In this case, you can use NSUserDefaults or you can post an NSNotification object from the poppedViewController. Though I am not sure, how much efficient these options are for you to use.
You can tell whether a controller appeared because it was added to the stack, or because another controller was popped off the stack using isMovingToParentViewController. If you have this code in B, it will tell you which happened:
-(void)viewDidAppear:(BOOL)animated {
if ([self isMovingToParentViewController]) {
NSLog(#"Coming from A");
}else{
NSLog(#"Coming from C");
}
}

Change which view opens first (Xcode) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to change the default View Controller that is loaded when app launches?
So if I made an app and a certain view opens first by default, and decide I want to change which view opens first, how would I do that?
That is controlled in the method in your AppDelegate.m file (or whatever the title of your app delegate file is) called didFinishLaunchingWithOptions. For example, in a tab bar app I've created it looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
All you have to do is change the value of the self.window.rootViewController. For example, let's say you want a MapViewController to become the first page to open. You could do something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
MapViewController *mvc = [[MapViewController alloc]initWithNibName:#"MapViewController" bundle:nil]; //Allocate the View Controller
self.window.rootViewController = mvc; //Set the view controller
[self.window makeKeyAndVisible];
[mvc release]; //Release the memory
return YES;
}

Resources