Xcode create action when switching views - xcode

hi there im having real trouble i have a main view which i am able to switch to 2 new views and i am able to switch back from both them views to the main view which is amazing
but i would like when i switch back from say the first new view to the main view i want a label to display text
and the same thing to happen when switching back from the second new view but with a different label
so to sum it up i want to switch views and have a label saying i switched back from view 1 being controlled by the button used to switch back
any help would be amazing

Just put empty UILable on Main View. And set its value when you are doing transitions form first view to main view or 2nd view to main view.

How are you switching between views? If you are using a NavigationController, just set a variable on the main controller before you push/present the child controller.
Then, you can use that variable to set the label when you return to the parent view (viewWillAppear event).

Related

What happened to "Is initial view controller"checkbox?

I just added a second view controller to my project, but when I went to set is as the initial view controller, the very convenient checkbox was missing (the Title label is also missing). I embedded it into a navigation controller just to see what was up, and the checkbox was available for the nav controller. We used to be able to have a project with two view controllers, no nav controller, and be able to simply check the box to set which was the initial. Is this a bug or a deliberate move away from the checkbox in anything that's not a navigation controller?
View controller (no checkbox):
Navigation controller:
That Inspector's contents look a lot like you have selected the view controller's main view, not the view controller itself.

How can I update a view controller when something happens in a container view controller?

What I need to do is be able to update my main view controller when something happens in a container view inside of it.
For example, if there was a nav bar at the top of a page with a save button. Below the nav bar is a container view and a form. The save button is greyed out until text is entered into the form and then it becomes intractable with the user. I want to do something similar so that the main view controller responds to something happening on the container view.
I can use a singleton create a boolean variable that changes when I want my code to run, but how can I make it so that once this variable changes to true, code on the other view controller runs and responds to this change?
I saw in this post that I could use delegates but it still leaves me with the problem of how the other view controller detects that the variable has changed - the method in this post was just another way of making the variable accessible from the other view controller I think.
I thought that I could have a while loop running checking the variable but this would freeze the main view controller until the while loop had finished - in this case when the variable was true wouldn't it?
Is there a way for a view controller to check if a variable has changed so that once it has, certain code can run afterwards without if freezing the view controller like I think a while loop would? Or a way for a view controller to respond to the value of a variable?
Thank you.
Have the main view controller listen for a NSNotification that tells it something needs saving. When text is entered, the controller that looks after the text field sends the notification.
You can attach the new text (or other information) to the notification if the target needs to know about its details.

Connect two NSObjectControllers within a multi view OSX Storyboard

I'm using Storyboards for the first time creating a master/detail view for a simple object.
Both view controller items of the split view have their own view & NSObjectControllers. The controller for the table view is a NSArrayController (which shows all instances of the Entity). The controller for the detail view is an NSObjectController, which shows just the selected instance.
When I click an object in the table, I'd like the detail to show up in the detail view. So I believe my goal here is to bind the 'contents' of the detail object controller to the 'selection' of the master array controller. However with storyboards I cannot cross view controller boundaries (can't create the IB 'link'. aka: can't bind cross VC).
Whats the best practice for doing this?
So far all I can think to do is manually set all this up in one of the controllers (either the root controller, window controller or perhaps the master table view controller) - but that seems counterintuitive. That seems to defeat the purpose of being able to lay out this stuff within storyboards in the first place, and my controller of choice would then have to know about the other controller specifically.
I must be missing something!

Storyboards: A loop of Modal Segues?

I want to implement something using Storyboards, but I don't know the best way to accomplish it.
I don't want to use a Navigation Controller, since I don't want the navigation bar at the top.
I just want the ability to switch from one view controller to the next.
I have a Main Menu view controller, which will segue into other views, and those views might segue to other views... Now, lets say that the last view in the chain has a "Return To Menu" button: should I just segue from that button to the Menu view controller? Or should I somehow dismiss all of the previous view controllers?
I don't need iOS to hold a copy of the Main Menu view controller after the user taps out of it, but I can't seem to find a way to just load a new view controller and present it, instead of having a parent view display it "modally".
Would it cause a memory leak if I just create a loop of modal segues?
(for example: Main Menu --> VC1 --> VC2 --> Main Menu --> VC3 --> VC4 --> Main Menu...)
Any help will be much appreciated.
Thanks!
Each segue creates a new instance of the destination view controller, so having a segue back to the main menu is not a good idea.
You would be better off dismissing the presented view controller(s), but note that it is possible to use a navigation controller without showing the navigation bar - the navigation controller has a property, navigationBarHidden, which you can set to hide this.

Xcode storyboard seque loops back to the same view

I am using storyboard seques to change views to other parts of my app but when I linked my main view to the next and called for the seque in the function within my enter button it just loops back to my main view and refreshes the app.
Here is my function call:
[self performSegueWithIdentifier:#"Enter" sender:self];
In the storyboard I have my main view linked to the next view with the identifier "Enter" but I still get send back to the same view. Is there any way to specify the destination of the next view? Do I need a certain variable from the other view controllers the need to be imported to the code of the main view controller?
I can provide more code or information if needed.
Picture: http://i1180.photobucket.com/albums/x411/Ryute88/screen.jpg
Identity Inspector Picture: http://i1180.photobucket.com/albums/x411/Ryute88/screen2.jpg
Picture 3: http://i1180.photobucket.com/albums/x411/Ryute88/screen3.jpg
Thanks in advance.
Please check this site: All about storyboarding
You will find details on doing your stuff.Try that and check if the problem still exists!
Are you using the write segue to call on the next view e.g. pop can only be used in case of Navigation Controllers.
In any case the problem will be trivial because storyboards do everything for you.

Resources