Calling multiple methods in viewWillAppear with a TabBarApplication - iphone

I'm currently working on an application that uses a view controller and a tabBar controller. When a tab is selected I'm using webservices to update this particular view. Each tab calls different services to display different types of data.
I use the viewWillAppear method to call methods when the different tabs are selected but what I would like to do is be able to setup some conditionals to only call the method for the current view/tab was selected.
One of my tabs has two views. Based on the view loaded I would like to call the methods in viewWillAppear that relate to the specific view.
How does one find out which tab-view is currently selected and which view has displayed?
Thanks

You can know which tab and View is being selected by Tag id given to each TabBar Item and View in your nib.
There are few questions on SO which can help you indirectly on this problem. One of them is
How to remember last selected tab in UITabBarController?

Related

Objective - C How to manage multiple views with View Controller iphone

I am new in developing iOS apps. I am trying to develop a multiple views app. My doubt is how to manage a multiple views app with View Controller, I mean, I do not want to use Navigation Controller nor Tab Controller.
My idea is to show a first View to choose the language, and after this, I want to show some different profiles in a table view. When you choose the profile, you get into a menu where you have some different functionalities (Once in this menu, I might use Navigation Controller).
My problem is that I don't know how to manage these two first views. I don't know if I have to declare them in the appDelegate, or if I can do it nesting one to other, I mean, I do the first view, and when I pressed the button, I declare the new view. Once in the new view, when I pressed a row in the table view, I make the another view.
I know it is a little bit confusing, so I hope you could understand it quite well.
EDIT:
I want to clarify that I am not using storyboards. My main doubt is what to do with all de view controllers, Do I have to declare all of them in the appDelegate? or Can I declare each view in every controller?
If you are using storyboards, you can use Segue's to navigate between the views, so you would show your first view, then you could tie a button to the next view (by control dragging in storyboard). If you want to transition programmatically you can use the performSegueWithIdentifier method. You could use the same approach to get from your tableViewController to your next viewController by using the performSegueWithIdentifier method from within the tableViewController's didSelectRowAtIndexPath delegate method (i.e. when a user taps a cell).
That should get you started. Good luck!
EDIT:
You really should be using storyboards. It's the way to do things these days. If you refuse, then the best approach is to create a container view controller that manages your "children" view controllers. You can find information on doing this, as well as the methods needed to present/remove child view controllers here:
Custom Container View Controllers
You can use navigation controller with "hidden" property.
self.navController.navigationBarHidden = YES;
If you want to have two different views and transition between them, you will want to use UIViewControllers presented modally. Here is Apple's Guide to this.

how to pass variables between a complex navigational stack

I have several uitableviews that the user can use to set different types of search parameters in my application, I will allow the user to select a cell that will then push a new view onto the stack in which the user can choose what to search and then return back to the original view with the value passed into the originally selected cell..
Where this gets complicated is that each of the original search views will be able to push the same view for search results onto the stack..
here is a graphical example of what I mean as it is hard to explain.
In this example only one viewcontroller can show at a time when a cell in the current view controller is selected the subview is loaded with the list of options, both view controllers use the same subviewcontroller.
My question is to do with returning values that you select in the subviewcontroller back to the correct viewcontroller...
I am trying to figure out how to return the selected value in the subviewcontroller to the correct cell in the correct viewcontroller.. I am hoping to get some suggestions on the correct way to handle this type of view structure as its not really covered in many books that I have available to me, plus I hope to draw on your guys knowledge and experience with similar projects.
One common way is to define a protocol in the sub view controller for callbacks, and have each of the main view controllers implement that... when they create or call up the sub view controller, they tell it that they are the selection delegate to be called when a change is made. Then they can also choose to dismiss the sub view controller.

Tabbar with different Data

I am trying to develope an iPhone App for 3 months.
I found everything myself in books or the internet. Now I have a problem that I am not able to solve myself.
I would like to develope a tabbar application with 3 tabs.
In each tab is a navigation controller with a tableview.
The tableview loads the data from an XML file on the web. The difference between each tab is only the difference XML-url. The tableview and function should everywhere the same.
What have I done?
Created a tabbar application
Put 3 Navigation Controller in the Tab Bar Controller in the MainWindow.xib
Every View in each Navigation Controller points to the same "TableView" class
Now it loads on every tab the same tableview. But I just want to change the XML-URL which is loaded. But I dont know how to implementate this.
I hope that somebody can give me a hint? Thank you!
Are you sure you need a Tab Bar? You could just add an additional level of navigation on top for the sources. So your navigation controller stack would be like
UINavigationController -> SourceViewController -> ListViewController -> rest of your navigation stack.
ListViewController is a subclass of a UITableViewController which is passed the source url based on selection from SourceViewController which can be a subclass of UITableViewController too. This will save you of the repetition you are trying to avoid and is more likely a better option for the thing you need.
Now if you insist on using a Tab Bar, your stack will be more like –
UITabBarController which will have three instances of UINavigationController each with its own instance of ListViewController which like before will be initialized using a source url.
Now it may be smarter to reduce it to a single ListViewController and attaching all the navigation controllers to it. You can do this using the -tabBarController:didSelectViewController: method in the tab bar delegate. On every tab change/call, you clear the current cache that is providing data to the table view and load the appropriate cache based on the source XML of that tab.
Usually state is preserved on tab changes but using this structure you will have to do additional work to get that.

Best Way To Create an "Add" View Controller

I have a table view that contains a list of Project objects. When an item is selected it brings up a detail view. Pretty standard. What is the best way to implement "add" functionality (popup a modal view controller to input new values and save the item)?
Currently I have view controllers for my root view, detail view, and add view. Essentially the detail view and add view are exactly the same except for a save & cancel button in the add view. Is it possible to reuse the detail view in the add view?
Finally, what is the best way to display the list of project properties in a grouped table view separated into sections?
Thank you for your responses.
Most likely, you are already passing your detail view controller a managed object that it is supposed to display when in detail view mode. When the user decides to add a new project, just create a blank object, pass it to the detail controller and display it. (You might want to insert this blank object into another "empty" managed object context in case the user cancels the add process to avoid having to clean up your main managed object context in that case.)
The detail view controller would also need a flag that tells it whether it is in edit or add mode so it can adjust its controls (and possibly delegate messages it sends to its owner) accordingly. You would set the flag to the appropriate value before you display the controller.
It sounds like you're looking for a UINavigationController. The UINavigationController lets you push new view controllers on top of existing ones. It gives you a navigation bar at the top that will allow the user to go back to the root controller. I think it's the kind of controller Apple uses it in the default email application, to give you an example.
Concerning organization: you design your root view controller and a detail/add view controller. In your app delegate, you attach a UINavigationController to the window and you set its root controller to the main controller you want to display. That root controller can then push the add/detail controller onto the stack (and when it does so, it can tell the add/detail controller which types of button to display.)
I can't answer your grouped properties question, but it sounds like a separate question anyway.

How can I update a view in the iPhone every time just before the view is displayed?

I have an application which has 7 tabs with associated views and view controllers. I need a way to update each view when it is selected. I have searched and searched, but cannot find a way to do this.
viewDidLoad will not work, as that only is fired the FIRST time a view is selected.
Capturing the selected tab in didSelectViewController won't work, because since there are more than 5 tabs, one of them is more and it is only fired for the tab itself, not underlying views when selected.
So I guess what I need to know is this: Is there a method I can call for on a view controller that will fire EVERY time just before that view is shown?
You need to implement delegate's -viewWillAppear:(BOOL)animated method for that.