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
Related
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];
}
i have an class instance and it methods in my ViewController.
Is it possible to get access of this instance and methods in the appdelegate ?
its like:
#implementation FirstViewController
#synthesize myObject;
- (void)viewDidLoad
{
[super viewDidLoad];
myObject = [[myObject alloc] initWithFrame:........];
[self.view addSubview:myObject];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[myObject doSomething];
}
and I want to call the same method in AppDelegate
- (void)applicationWillResignActive:(UIApplication *)application
{
[myObject do Something];
}
Someone an idea ?
greetz
You can get the controller from rootViewConroller like this and call the fucntion of it
- (void)applicationWillResignActive:(UIApplication *)application{
UIViewController *controller = self.window.rootViewController;
if([controller isKindOfClass:[UINavigationController class]]){
FirstViewController *firstViewController;
for (id vc in [((UINavigationController*)controller) viewControllers])
{
if ([vc isKindOfClass:[FirstViewController class]])
{
[((FirstViewController *) vc) doSomething];
break;
}
}
}
else if([controller isKindOfClass:[FirstViewController class]]){
[((FirstViewController *) controller) doSomething];
}else{
//Not found
}
}
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;