IUNavigationController loading more viewControllers - iphone

Not a Noob as yesterday, but still green.
I have a UITabbarcontoller and a IUNavigationController they seem to work fine. I have a UITableviewController to which I loads my NSMutable array. The user clicks a cell and didSelectRowAtIndexPath xib is loaded onto the stack. I have a 'Learn More' button on the current xib. I've tried a few approaches to load a newer xib when the 'Learn More' button is pressed but have failed. Im thinking it has to do with the Navigation Controller? Do I need to import the navigationcontroller to every ViewControllerSubclass I make? Thanks.

Usually one calls:
[self navigationController] pushViewController:newViewController animated:YES]
to push a new controller onto the view stack. So when the Learn More is pressed, you create a new controller (-initWithNibName:bundle:) and load it using that. Be sure to release the new controller.
Look at the UIViewController documentation for more.

Related

making a custom back button in iphone

I am new to iphone so I have a very simple question. I am using a storyboard in xcode 4.2. I have multiple screens with about buttion in each viewController.
Now I have created segues ofc. Each about button i have linked with about viewController. However I am not using a navigation controller.
I have custom made a back button. How can i go back to the screen which brought me on the about section.
Best Regards
If you are modally presenting the new view controllers they can be dismissed using the following.
-(IBAction)myCloseAction:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
As you are not using navigation controller, u need to manually do the pushing and popping viewcontroller. When u change the viewcontroller, store previous viewcontroller reference in the new viewcontroller and when back button is pressed goto the previously stored viewcontroller.

popToRootViewControllerAnimated doesn't modify attached navigationItem

My UIViewController calls a function on my rootViewController which then called popToRootViewControllerAnimated to return the view to the rootController. This all works - great!
Unfortunately the UINavigationItem (toolbar at the top) seems to display a mashup of both the rootViewController and the UIViewController that has just been removed.
What do I need to do? What have I done wrong?
The navigation bar doesn't remember changes that were made to it, so when you push a new controller, the navigation bar is altered to give the title of the new view controller, but it doesn't store what was there for the previous view controller.
You will need to recreate the items in the toolbar each time you come back to the view controller that has custom items.
You might be able to do this on viewWillAppear instead of viewDidLoad. I can't recall exactly, but you should recreate custom controls on navigation toolbar because it does not get preserved when a new view controller is pushed.
It seems that calling popToRootViewController from the rootViewController messes things up. TO rectify this I called the following from within the calling UIViewController
[self.navigationController popViewControllerAnimated:YES];

Getting empty view and blank navigation bar when I use popViewControllerAnimated

I'm writing an iPhone app that is based on a UINavigationController. I'm pulling data from a server that sometime returns bogus links. I open each link by pushing a webview viewcontroller. I want to be able to include some error handling. I know if the link is no good. So I want to be able to pop the webview view controller as soon as I know that my webview has encountered an error.
Currently, I've tried using the following code:
[self.navigationController popViewControllerAnimated:YES];
I then get a Navigation bar with nothing displayed in it, but if I click where the "back" button should be it operates appropriately. The title pops up when I click where the "back" button should be. The view where the viewcontrollers usually display there content is blank white too even though I'm popping back to a UITableViewController.
I've tried this as a workaround:
UINavigationController *nav = self.navigationController;
[self.navigationController popViewControllerAnimated:YES];
[nav.visibleViewController.view setNeedsDisplay];
I've checked the viewControllers array in the UINavigationController and it has the right viewcontrollers in it (ie it has removed the viewcontroller for the webview).
I also tried putting code in the viewWillAppear of the viewcontroller I'm popping back to, but the method is never getting called.
I'm looking for a way to force the UINavigationController to reload the same way that you can call reloadData on a UITableView.
Any help would be greatly appreciated.
I saw something like this on my app where I was using a navigation bar I added in Interface Builder on the root view of a navigation controller and then programmatically creating the nav bar and its subviews for the second view. When I would pop the second view to return to the first view I would hide the self.navigationcontroller bar which would show the white space underneath until the IB nav bar of the previous view appeared. To fix this I decided to stick with programmatically creating all my navbars which fixed the issue for me.
TL;DR - if you are using both IB and programmatically made navbars this can happen when popping views, stick with one or the other for all the navbars yo

Opening Another Xib form an Xib

Not a Noob as yesterday, but still green. I have been playing around with the code that Elisabeth Robson has put together HERE. I have a UITabbarcontoller and a IUNavigationController they seem to work fine. I have a UITableviewController to which I loads my NSMutable array. The user clicks a cell and didSelectRowAtIndexPath xib is loaded onto the stack. I put a 'Learn More' button on the current xib(BookDetailView). I've tried a few approaches to load a newer xib when the 'Learn More' button is pressed but have failed.
Ive Tried IBAction and Pushing the Newer xib to the top.
Do I need to create another view controller?
Thanks for looking.
I suggest linking your UIButton to an IBAction
-(IBAction) learnMoreClicked;
You will need a ViewController for your "learn more" view and in the IBAction method, you load it as follow:
[[LearMoreViewController alloc] initWithNibName:#"LearMoreView" bundle:nil];
Then you can either push it on your navigation stack or as a modal view.

iPhone: How to Trigger the Loading of a View Using a UI Element in a Previous View

I've been reading the Head First iPhone Development book and I understand how to get to a new view from a table but how exactly would I be able to get to a new view or view controller, by just simply pressing a button? Is that even possible?
I mean there are some apps where you click a button, not a table cell and it loads a new view. How exactly is that done? If someone could help out a newbie it would be greatly appreciated!
I think what you're looking for is a modal vew controller. THis presents a modal view like you described on top of everything else. If rootViewController is the view controller that is displaying your current view, and myNewViewController the view controller you want to display modally:
[rootViewController presentModalViewController:myNewViewController animated:YES];
There's plenty of examples of this kind of thing on the net, just search for presentModalViewController
Like bpapa said in the comments, it's hard to be specific without code. However, generally what you want to do is:
Build a navigation controller that contains one original view.
Create a button in your original view using the Interface Builder.
Build a callback method (usually defined with IBAction) that is run when the button is pushed.
In that callback method, create a new view and push it onto the navigation controller the same way you would using a table view cell.
Alternately, if you only want one level of hierarchy, you could use a modal view controller; instead of pushing onto the navigation controller in the last step, just present the modal view controller.
The general answer is that you have an object that manages which view controller loads when.
The most commonly used is the UINavigationController. It is a UIViewController that instead of controlling views, controls other view controllers. It works like a simple stack. You push views you want to display onto the nav's controller stack and when you want them to disappear you pop them off.
A common (though sloppy) way of using a nav is to make it a property of your app delegate. Then anywhere in your app you can references it by:
UINavigationController *nav=[[[UIApplication sharedApplication] delegate] navigationController];
The view controller for the first the user sees is held in the nav's topViewController property. If you want to load a view based on a user action in the topViewController.view, you would have something like this:
- (IBAction) loadNextView:(id) sender{ // Action called by a a UI event such as a button press.
UINavigationController *nav=[[[UIApplication sharedApplication] delegate] navigationController];
UIViewController *nextViewController=...// load from nib, connect with IBOutlet, create programmatically
[nav pushViewController:nextView animated:YES];
}
The first view disappears to be replaced by the next one. To return to the first view, you have a method in the next view controller like so:
- (IBAction) unloadSelf:(id) sender{ // Action called by a a UI event such as a button press.
UINavigationController *nav=[[[UIApplication sharedApplication] delegate] navigationController];
[nav popViewControllerAnimated:YES];
}
... and the nav returns you automatically to the previous view regardless of what that view was.
When you first start out, especially if you use Interface Builder, the structure of the app is largely hidden. Behind the scenes all view controllers and their views exist in a hierarchy of some kind that leads back up to the app delegate. You should train yourself to think in hierarchal terms even if it is not immediately obvious how that hierarchy is constructed.