back button wont work.. Iphone - iphone

I have 2 page controls in my app, one for category and when i click details button of that category other page control comes.
I have pushed the first view controller and used present modal view controller. Now a need to go back to the home page from the category page control but the view did load and view will appear wont work. That is where i have added my navigation bar programmatically. is there any way i can call them?
i am new to iphone programming. Please help me if you can....
Thankyou

You can use delegate.
Set the object that created your new view controller as delegate. When you presenting your view controller add it to navigation bar. Setup your view controller with cancel/done buttons and set them up to pass the messages to delegate.
When user selects cancel/done the delegate method is called. Delegate can then dismiss the view controller.
See the example in View Controller programming guide for iPhone OS.
You'll have to setup the buttons and call to delegate when you create your view controller.

If you have used "present model view controller"
then you required to use "dismis model view controller" instead of using "pop view controller" for going back...

Related

Persistent UIBarButtonItem on all navigation bars within tabbarcontroller

Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.

Is there a way to access the view controller that initiated a modal view from that new modal view?

I have a view that has an "Add" button in its navigation bar. When clicking that button, it slides up a modal view with a form for them to add their item. I would like to inform the calling view controller (the one that had the "Add" button) that the expense has been added so it can do any updating it needs to do. Is there any way to get access to the view controller that initiated the modal view?
There are two ways that come to mind. Either create a protocol that your modal view uses to inform the calling viewController or by having your modal view post a NSNotification that the calling view controller is observing. In the case of posting the notification, you would send the expense in the userInfo dictionary of the NsNotification object.
Good luck
I believe this property will work parentViewController
Here is a link to the description
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController
if you are in iOS 5.0 you should access this information with presentingViewController property, and for iOS 2.0 to 4.X parentViewController property works.

get rid of navigation bar in view controller iphone sdk

I am basically creating an app that looks like a power point presentation. every time the user clicks on a button I add another view controller. So here is what I have:
This is the ViewController that I want to add when the user want's to go to the next slide:
I have a button that when clicked it shows this view controller. In this example it will show nothing because the view controller is empty.
so when that code get's fired this is what happens with my iPad:
It loads that view controller perfectly fine but with the navigation bar at the top. How could I get rid of that navigation bar? I think the problem is the code because the view controller is empty. I know just the basics of objective-c so I have not been able to fix it with code.
Insert this line of code before presenting your navigation controller modally:
[navControl setNavigationBarHidden:YES];

UINavigaiton controller from a view based application

So I have an app. On the mainWindow I have 1 button. When that button is pushed i want it to open up a completely separate file and start a navigation controller. How can I achieve this all the sample code that I look at base the view controller out of the app delegate.
Basically what I want to do is create something like the facebook application where there is an index of buttons then when one it opens up a navigation controller.
The app delegate is really the start of the application so it makes sense that the view controller is based there. For each new page you create, you just add on another view. Within that view, you can put the navigation controller or whatever you like.
So in the app delegate files, create an action that connects to your button. Have that action push a new view controller onto the window. Then in the new window, instantiate a navigation controller.

Do you have to create a View Controller to move between views?

I want a single startup view with a button and a welcome screen. When the button is pressed I then want to navigate to a second view which contains a table view and toolbar.
I've tried creating a ViewController but my button is shown on all views. I just want a single view, then when it's pressed i go to the next view and the 'real' app starts. Can someone please try and explain the best architecture to do this?
(like in chapter 6 of beginning iPhone 3 Development by Dave Mark and Jeff LaMarche )
Thanks
Are u developing for the iphone or ipad, if its for the iphone then have u looked into UINavigationControllers? These allow you to interchange from view controller to view controller in an easy fashion.
So for your problem I would have 2 view controllers one for the startup and one for the table view view controller. Assuming you set up the Navigation controller right (which you can easily by starting a new project with a navigation based viewcontroller through xcode), then you can use [navigationController pushViewController:viewCOntroller) method to present your view controllers view, also viewcontrollers have their navigationController as a property, so when the button is clicked all you should have to do it
new up the viewcontroller whose view you want to display
and call (from the current view controller ) [self.navigationController pushViewController:] method to display your second view controller.
release the view controller u just pushed
Navigation Controllers also have a navigationBar property which you can use to go back and forth between view controllers.. heres the class reference and it contains a guide of how to use these..Navigation Controller Reference