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

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.

Related

Laravel multiple model bound forms in a parent view

The overall concept that I'm attempting to do is create admin panel that has multiple "forms" on a single blade view. Each "form" is a blade.php file that has a form that is model bound to provide quick access to the model data on load. For example, let's say that I'm running a manufacturing line and there are three models (subviews) that I want to #include() on manufacturing.blade.php.
Parent view (manufacturing.blade.php)
Subview - Start time (start-time.blade.php)
Subview - Throughput (throughput.blade.php)
Subview - Supervisor (supervisor.blade.php)
Each subview has a submit button on it that POSTS to the assigned resource controller. My problem is how do I successfully load manufacturing.blade.php and include form model binding when I never call the index controller on the subviews.
Is what I'm asking even possible?
For what it's worth I figured it out right after I posted the question. The variables required for the model binding inside the subviews were the problem. I was receiving errors about the variables not available, blah.... when I loaded the parent view page. Obviously the variables aren't available when I call the subviews because they were never pulled in from the parent view. In other words I'm trying to access something that isn't there.
Solution:
In the parent view loading controller, perform all the necessary db call to obtain/generate the objects required for the subviews. After the objects are obtained use
View::share('startTime', $startTime);
View::share('throughput', $throughput);
View::share('supervisor', $supervisor);
That method (view::share) allows that variable, 'startTime', etc..., to be shared across all the blade views that reside inside of parent. Just be sure you add the lines right before you return the intended parent view from your controller.

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.

Calling a function when a view controller is dismissed (xcode/iOS)

I have a main view controller. When a specific button is pressed, I present another view controller. When the second view controller is dismissed, I want to call a function in the main view controller. Originally I thought I could just use the completion handler for presentviewcontroller, but now I'm thinking that is not the way to go. Any tips on how I can accomplish this? I'm pretty new to this, so any help would be appreciated!
Assuming your main view controller is the second view controller's parent, you can access the method with:
[[secondViewController parentViewController] method];
Beware -- if you are using a navigation controller, the parent view controller will be the navigation controller. In this case, you will have to query the navigation controller's stack.
Good luck!

Where does the program return to when one view calls a 2nd view and the 2nd view closes?

I've been working all day on that classic problem of passing variable values between views. (I've read and typed in almost every example I've found in my books and on the net!)
My second view is a picker, and I have to retrieve the row value and send it back to the calling program. I've managed to pass data from the first view to the picker's view, but what method runs in the first view controller when the 2nd view controller closes? That is, where do I put the code to receive the picker's value?
Incidentally, I settled on the Shared Instances method of passing the values, found at http://www.cocoanetics.com/2009/05/the-death-of-global-variables/
Thanks,
-Rob
I found an answer to my question in Sams Teach Yourself iPad in 24 Hours. The code goes into the viewWillAppear method. It's like ViewDidLoad but it's for returning to the View from a different View. If you are updating a label, for example, on the first view with data set by the second view, the data being passed is set into the label in viewWillAppear.

Joomla 1.7 custom toolbar button usage

I've added a custom button into my component's backend toolbar with this code:
JToolBarHelper::custom('libri.details','details.png','details.png','TOOLBAR_DETAILS',true);
This button needs that the admin checks one of the entries listed in the table.
You can see a screenshot here if you haven't understood what I'm talking about
The button is the one called "Dettagli" (no image at the moment).
I'm having some problems:
How do I append the checked entry's id to the address generated from the button?
I've put a details() method into the controller, it calls an instance of the model and a method inside it. The model's method returns to the controller the result of a query. How do I say to the controller to pass that result to a view called libro?
All information in the page will be sent through POST to the Joomla controller (in this case, libri). In your controller, you can use JRequest::getVar('varNameHere'); to retrieve it.
$this->setRedirect($urlOfView, $someStatusMessage)

Resources