I', performing a basic push segue (working with nibs) and from one view controller to another table view controller, and from some reason the 'Back' button is not appearing, that normally it does appear.
This is how i'm performing the push:
#interface HomeViewController ()
#end
#implementation HomeViewController
- (id)init {
self = [super initWithNibName:#"HomeViewController" bundle:nil];
if (self) {
// Do something
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (IBAction)goToStack:(id)sender {
StackTableViewController *stackViewController = [[StackTableViewController alloc] initWithNibName:#"StackTableViewController" bundle:nil];
[self.navigationController pushViewController:stackViewController animated:YES];
}
In your StackTableViewController, you should set setNavigationBarHidden to NO
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
To make sure the navigation bar reappears every time you navigate away from your view controller (HomeViewController), use this:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Related
Present view controller is not working with ios 9,
when I press the button it not redirected to present view controller.
Why this happens ?
I had tried the below code
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
I had also tried the below code
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Registration"
bundle:nil];
RegistrationViewController *add =
[storyboard instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:add animated:YES completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:add
animated:YES
completion:nil];
});
}];
Edit
My complete code here. I am using Xcode 7 and running it with ios 9
#import "LoginViewController.h"
#import "RegistrationViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionRegistrationClicked:(id)sender
{
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
#end
Registration view controller
#import "RegistrationViewController.h"
#interface RegistrationViewController ()
#end
#implementation RegistrationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Make sure the presentedViewController is nil. If presentedViewController is not nil change the code to following.
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:#"Registration" bundle:nil] instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
if ([self presentedViewController]) {
[[self presentedViewController] dismissViewControllerAnimated:NO completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:viewController animated:YES completion:nil];
});
}];
} else {
[self presentViewController:viewController animated:YES completion:nil];
}
try viewDidAppear in
-(void)viewDidAppear:(BOOL)animated{
[self presentViewController:viewController animated:YES completion:nil];
}
Try the below code:
RegistrationViewController * viewController = [[self.storyboard instantiateViewControllerWithIdentifier:#"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
I have view controller transition like vc1 -> vc2 -> vc1. And I need the UINavigationBar be hidden in vc1, and showing in vc2.
I do the following:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = NO;
}
In iOS6, it works fine. But in iOS7, when I back to vc2 from vc1, the navigation bar is not hidden but moved upward behind the status bar, the bar got hidden after the transition animation finished.
How can I really hide the nav bar?
Try like this:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO];
}
or try like this :
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
In VC2 Controller put this in - viewDidLoad
[self.navigationController setNavigationBarHidden:NO];
In VC1 controller put this in -ViewDidLoad
[self.navigationController setNavigationBarHidden:YES];
then VC1 add this also
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
I hope it will be helpful for you...
How can i make it so the nav bar is hidden on the first view only, i have some code that will let me do it but if i go to my second view then back to my first i can see the nav bar slide up is there any way to make it so it doesnt do that. here is the code i have.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:(BOOL)animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
In first view
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
In second View
-(void)viewDidLoad:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
You can just have an instance variable and keep track of whether it's the first time the view is appeared, ie. BOOL isFirstTime make sure to set it to YES in your viewDidLoad and pass it to setNavigationBarHidden: in viewDidAppear:
- (void)viewDidLoad
{
[super viewDidLoad];
isFirstTime = YES;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:(BOOL)animated];
[self.navigationController setNavigationBarHidden:isFirstTime animated:animated];
[super viewWillAppear:animated];
isFirstTime = NO;
}
Do something like this:
#interface MyViewController : UIViewController
#property (nonatomic) BOOL shouldHideNavBar;
#end
#implementation MyViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:self.shouldHideNavBar animated:animated];
[super viewWillAppear:animated];
self.shouldHideNavBar = YES;
}
#end
The first run though, the default value for shouldHideNavBar is NO. After viewWillAppear gets called for the first time, it is set to YES. So, next time viewWillAppear is called, your nav bar will be hidden.
So, I think that when I click outside of a popover, the method popoverControllerDidDismissPopover should be called. I know this isn't called when dismissPopoverAnimated is called.
I have a simple project that I have setup that shows popoverControllerDidDismissPopover just isn't called:
#import "ViewController.h"
#import "PopoverViewController.h"
#interface ViewController ()
{
PopoverViewController *controller;
UIPopoverController *popoverController;
}
#end
#implementation ViewController
#synthesize button;
- (IBAction)showPopover:(UIButton *)sender
{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake(self.button.frame.origin.x,
self.button.frame.origin.y,
self.button.frame.size.width,
self.button.frame.size.height);
[popoverController presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
controller = [[PopoverViewController alloc] initWithNibName:#"PopoverViewController" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(#"Why am I never called!!!!");
}
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return true;
}
#end
Please tell me where I'm going wrong or how I can detect when a popover is dismissed.
The whole project is here:
https://rapidshare.com/files/3182903825/PopoverDemo.zip
You never set the delegate for your popoverController to self.
_popoverController.delegate = self;
You didn't set the delegate of your popoverController. Add the following code to the end of the viewDidLoad method:
popoverController.delegate = self;
Good day to you guys
I have an application that has a UITabBarController for tabbed-navigation... The view-controllers are mapped to their respective TabItems via a URL, just the same as that of Three20's TTNavigationSample App.
My problem is that inside a view controller of mine, i have a button that calls to another view controller which is also attached to a TabItem. When i trigger the button, the application throws an error. How can I resolve this?
In my TabBarController, i have this inside the viewDidLoad method:
-(void)viewDidLoad {
[self setTabURLs: [NSArrayWithObjects:
#"tt://bulletinBoard",
#"tt://contacts",
nil
]];
}
Sample .m file
#import "HabBarController.h"
#implementation TabBarController
- (void)viewDidLoad {
//these are variables like "tt/feed"
[self setTabURLs:[NSArray arrayWithObjects:
kAppFeedURLPath,
kAppHotURLPath,
kAppPostPhotoURLPath,
kAppGeneralActivityURLPath,
nil]];
}
- (UIViewController*)rootControllerForController:
(UIViewController*)controller {
if ([controller canContainControllers]) {
return controller;
} else {
UINavigationController* navController = [[[UINavigationController
alloc] init] autorelease];
[navController pushViewController:controller animated:NO];
return navController;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.tabBarController.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end