iOS 5.x - Detect when a view appears on screen - ios5

How do I detect when a certain view appears while the app is running? e.g. in a tab bar app let's say we have 2 bars "Results" and "Edit" - the app loads with results and there is nothing. Now, users goes to edit and makes some magic. Then, he presses the results bar again, and he will see the results. In other words, I need to pass the information from "edit" view controller to "results" view controller when the results bar is pressed. I hope I made this clear. Thanks in advance!

There's a few ways to approach this problem.
1) you could keep a handle (or pointer, or property) to the "Results" view controller from your "Edit" view controller and when you want to send data to "Results", that'll be easy to do (via a method or a delegate protocol).
2) you could register the "Results" view controller for notifications and then when you want to update it with any new data, populate your fields when the proper notification comes in. And over in your "Edit" view controller, post a notification with a dictionary and/or object that encapsulates the results you want to display.
And there's more!

Related

iOS 10 go back to root in nav stack with parameters

I have an initial ViewController that is a TableView with lots of data. I have a title bar button item that links to another TableView with a summary of the data in the first ViewController. I currently have it so that when you click on a cell, it redirects the user back to the first ViewController and scrolls them to the proper cells. However, it adds the view to the stack and doesn't actually move them back properly. I think I would be able to do this through Unwind segues, but I can't seem to get them to work through cell clicks. Is there a better way that I can achieve this?
When I switch to the other view, I also need to set two variables in the initial controller to tell it what index to scroll to.
1.UNWind Segue :
suppose that we need to programmatically trigger the backward navigation, based on an interaction with something other than the default “back” button on the navigation bar. How would you do it? Yep – you’ve got it: by using an unwind segue.
2.Other way is usual : PopViewController Method
As per your question , you can go with option 2 which is more easy .
As far as Sending data from SecondViewController to FirstViewController you can use delegate pattern to send data back.
Here is few useful post : https://stackoverflow.com/a/25523091/3400991
Feel free to comment. Thanks

Xcode - Manually load a view controller

What I am asking may be impossible and sound weird, but here it goes.
Here is similar to what I want to achieve:
A user opens the app for the first time, there are two tab bars, in the first one (he has not tapped the second one yet) he presses a button that should initiate a progress view and text view changes and other view changes EVEN THOUGH the user has not loaded the other view controller by clicking the second tab bar.
So, is there a way to generally load a view controller before the user manually loads it himself, I know calling viewDidLoad manually will not help, any suggestions? Pretty confusing, it is like modifying a view but the controller has not loaded yet...
Thanks!
Make the changes in the other view controller and then let the controller configure its own view when it does its natural loading.

how to share data between views with navigation controller iphone

i have a view which is fetching data from an Array and presenting the data in a tableview. This view has a navigation controller with a button in it. The button is meant to take you to another view for advanced searching. Let's say that in this new view i have a picker, when the user selects a value from the picker and clicks the back button in the navigation bar i want to get the value that the user selected. What is the best practice to do that? How can i send the selected value from one activity to the previous one?
Thanks in advance.
What you need here is reasoning a bit in terms of the Model-View-Controller design pattern.
Views should get their data through the model. So in your advanced search view, when the user selects some value, this value is stored in the model.
When you go back, the first view redraw itself by reading the current search value from the model.
There are other possibilities, like having the search view controller own a pointer to the first view and sending a message to it when the search value changes, but this is not very modular and is pretty fragile.
Use delegation. Write your own protocol like "PickerViewDelegate". then implement this protocol in your "main view" (which has table view). in PickerView just invoke [delegate somethingPicked:something].
I'm not sure, that search value is a model entity.

Reload View only when application is opened Again

My application has tab bar with one of the tabs having a segmented control on navigation bar.
Based on segment clicked different view is displayed using a url.
I am calling the url in viewdidload method.I do not want to use viewwillAppear to call the url as it will be called each time the view is displayed.
I only want to call the url again whenever user closes the application and comes back.
Whats the best way to do this.Should I remove the view controller from and reload it again once the application is opened.
Please use a more descriptive title for your question next time!
There are notifications for this that you can observe in your application:
UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification come to mind.

Transitioning to a view of unknown type in a navigation-based iPhone app

In my iPhone application, a user selects an item from a UITableView to choose a resource to view. The UIViewController subclass required to handle the resource is not known until the resource is retrieved, which may take a few seconds.
In response to the selection action, I push a "loading" view controller on the nav stack. That controller presents a view with a UIActivityIndicatorView along with (possibly) other status information, and initiates the download of the selected resource. From this view, the user might cancel the download, in which case I would return to the list of resources. If the resource arrives, though, an appropriate new view controller is created corresponding to its type.
Here's where it gets sticky. If I push the new type-specific view on the nav stack, the "loading" view is still in the stack; obviously once the loading is complete, there's no need to "go back" to that view. I've tried simply adding the type-specific view as a subview of the "loading" view, but that doesn't get my type-specific controller onto the nav stack, so it doesn't have a [self navigationController] for further navigation.
How can I "replace" the current view on the nav stack with a new one? Or, more generally, how can I show activity / progress when I don't yet know what controller will be used to display the resource being retrieved?
I've found pretty cool "HUD" progress indicator classes, but I don't want the progress indication to appear on top of the list of items being selected from. Instead, I want the user to perceive that they have "gone" to a new space that is waiting to be filled in.
I'm pretty new at this stuff, so I hope I've at least worded the question coherently. Thanks for any help anyone can provide.
Update: Actually, it would probably be better to display your "loading" view as a modal view. Check out this question for a few examples.
You should pop the "loading" view controller and push the "specific" view controller once the latter has been downloaded and allocated. Play around with NOT animating one or both of those actions to see what gives the best experience.