Switching from one view controller to another automatically - xcode

I have a project where a user fills in a web form, once the user hits submit it moves to a viewcontroller that shows a message "sent" or "error".
How can I make it automatically move to the main view controller without pressing a button, after a certain amount of seconds (so it displays the message "sent" for approx 2 - 3 seconds then moves to the main vc)
Any information would be highly appreciated, thankyou
Sean

You should be able to show the view and, in the viewDidLoad method (or viewDidAppear), set a timer to call a method that dismisses the view controller. Use performSelector:withObject:afterDelay to perform the delay.

Have a look here:
How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?
You can trigger some code inside a block to run after a specified delay. Inside that code you can include your code to navigate to the other view controller.
The code for doing this depends on whether you are using storyboards or not. If you are using storyboards, you can use:
[self performSegueWithIdentifier:#"MySegueName" sender:self];
If you are not using storyboards, you can use the following to display the second view controller modally:
[self presentModalViewController:myNewViewController animated:YES];

Related

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.

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.

Adding a delete button to a CPTableView column in Cappuccino

This seems like it would be an easy thing to do but I am having a lot of trouble getting a button to respond to events while in a CPTableView. Here is the initialization code:
//deleteColumn is hooked up to CIB table column.
[deleteColumn setEditable:YES];
[deleteColumn setWidth:24];
var deleteButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
[deleteButton setTarget:self];
[deleteButton setAction:#selector(deleteClicked:)];
[deleteColumn setDataView:deleteButton];
I then have this selector code in the same view controller:
- (void)deleteClicked:(id)sender
{
console.log(sender);
}
It seems the table view is squashing any mouse clicks inside it because I don't get the console log when I click the button.
Is there an easy way to do this? All I want is a button that deletes corresponding row in the table.
The CPTableView takes over the action of the button for its own purposes. Try listening for the regular edit delegate message CPTableViewDataSource:tableView:setObjectValue:forTableColumn:row: in your table delegate.

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.

Tableview reloadData is not being executed -- sometimes

I have a view controller that is called from 2 different places.
1) I call it from a root controller. It is shown and populated. The add button works perfectly. I open a modal form, get the information and return it to the view controller via it's delegate.
- (void)itemsAddViewController:(AddItemView *)itemsAddViewController didAddItem
(OrdersDetails *)orderDetail;
{
if (orderDetail) {
[orderDetailItems addObject:orderDetail];
}
[self fetchOrderDetails];
[lineItemsTableView reloadData];
[self dismissModalViewControllerAnimated:YES];
}
However, when I call it from another view (on the right side of the split view), this same code does NOT reload the table. It adds the data -- if I leave the form and come back, the data is there, but the tableview is not being refreshed. When I step through the code, it gets the the line, but then goes over it like it doesn't see it.
When a modal view controller is presented over the view controller containing -itemsAddViewController:didAddItem: the underlying controller's view is not visible and will therefore be unloaded if the controller receives a memory warning.
As a result your view may not be loaded and your lineItemsTableView outlet may be nil when you call -itemsAddViewController:didAddItem:. Your call to reloadData would need to move to -viewWillAppear: to avoid assuming that your controller's view can have a persistent state when it is not visible.

Resources