What's the order between pushing a view and viewWillAppear? - objective-c

I made a viewController class which has a button, an input and a label.
What I want to implement is that when user click the button, a new view will be pushed and the input text will be showed in the label.
I used UINavigationController to memorize the text in input and set the logic in 'pushNext', which is the IBAction of the button, and the viewWillAppear method is used to put the text stored in UINavigationController into label.
I used NSLog to track the proc, and found that viewWillAppear always be called earlier than pushNext? But when I run the example code in my book, the called order was oppsite!
Why? Is there any attention to use these two methods?

The order should be
viewDidLoad
viewWillAppear
viewDidAppear

Related

Dismiss modal segue

I am trying to understand modal vs push segue and read few Q & A like this and this. One point I am confused from these answers is "The presenter should take care of dismissing the VC it presented."
For example, the example I am writing shows UIPageViewController something like the example available here, with a button at bottom of the page with name "Skip".
In story board I have created a segue (of type Modal) from "Skip" button to another "View Controller" (let us say LoginViewController), but where do I need to dismiss the UIPageViewContoller (if at all required) and how?
EDIT:
After little bit more reading, it seems UIPageViewController (Which has Skip button) should take care of dismissing LoginViewController (because UIPageViewController is the presenter).
In my case, after Login complete, I would like to navigate to "Menu" page, then how can I ask UIPageViewController to dismiss the "LoginViewController" and move to MenuController? I couldn't find any example on how this works.Any help would be appreciated!
As per the tutorial link you have given in question.
There is a APPViewController which is root for the UIPageViewController and also in AppDelegate, so on top of that view, require a Skip button which is above all the subViews in AppViewController. So its IBAction event will be in AppViewController only.
Now first change your AppDelegate self.window.rootViewController to LoginViewController.
In LoginViewController viewDidLoad event, presentModal UIPageViewController.
Now in its action event of skip button, you can write like this:
[self dismissViewControllerAnimated:YES completion:nil];
So it will automatically dismiss all your AppChildViewControllers, and will display LoginViewController, which is already behind.
This is just a base logic to achieve your goal, you might require to change code as per your project implementation.
Hope this helps.
First dismiss the UIPageViewController and then using delegate or block methods (whatever suitable) to get notified when you press the skip button in the parent controller and then calling LoginViewController.

3 programmatically created UIButtons - how to go between 3 UIViewControllers using those buttons with Storyboard?

Playing around with some Objective-C (well, iOS) and have done the following... loaded some UIButtons programmatically into a UIScrollView. That works well. Though I've always just connected UIViewControllers together using control-click and drag. Now I've created buttons programmatically, I have no idea how to go from one view controller to another in a Storyboard because there is nothing to drag from!
I'm not really sure what code to post as such, because I haven't done anything that /nearly/ works or doesn't work as such. I get how to do it with XIBs. But I suppose the question is : 3 UIButtons have been created programmatically and I have 3 UIViewControllers. How do I access those ViewControllers using my UIButtons?
Thanks
In the Interface builder view control click and drag from the viewcontroller icon under the first view controller, to the middle of the second view controller. A segue will be created, selected the appropriate type.
Now select the segue and in the inspector give it a unique identifier (say 'myNewSegue').
Now in your first viewcontroller you can create a method that has the following code:
-(void)myButtonAction:(id)sender {
[self performSegueWithIdentifier:#"myNewSegue" sender:self];
}
And add this method as a target action to your button:
[myButton addTarget:self
action:#selector(myButtonAction:)
forControlEvents:UIControlEventTouchUpInside];]
A segue doesn't have to have a button at the leading end of it; you can instead draw it from an entire view controller to another. You can also give a segue an identifier, a string that's used as a name for that segue. Once you've done that, you can programmatically trigger that segue by calling -performSegueWithIdentifier:sender:.
To actually call -performSegueWithIdentifier:sender:, though, you'll need to connect the button to a target and action. If you've never done that, read the Event Handling Guide for iOS in your documentation.

Catching Button Events from Different ViewControllers

My Setup
I have a ViewController, where users type some sort of text in there. Call it InputViewController.
I have a UIView (in a separate class), where I draw a navigation bar that has a gradient (I override drawRect for Core Graphics, hence I need to to have in a separate class) which has a button. The button takes you to a MapViewController, which allows you to add a location tag to your input. Once a location tag is added, I would like to change the button's image.
My Problem
Once the button is tapped, I need to send the user's input to the MapViewController, where a delegate is also implemented and will pass back some information back to the InputViewController. The issue here is that the button resides in the separate UIView. One way to do this is pass the UIView the information once they are set, which in turn would be passed to the MapViewController once the button is tapped. The problem here would be the delegate as the delegate needs to return to the InputViewController and not the `UIView.
I was wondering if its possible to move the UIView into the InputViewController, including the drawRect method for that view. If so, how can I do that? If not, what are other ways/suggestions I can do to have the above set up?
I guess you need to use NSNotifications for sending messages to your classes. See this.

How to enter delete confirmation state UITableViewCell from custom action?

I have a problem, I want to show right delete confirmation button of my UITableView's cell. Swipe to delete works just fine but I also want this to happen without swiping.
I would like to change cell's state from default to showing delete confirmation. There is bool property showingDeleteConfirmation but it's read only.
[self setEditing:YES animated:YES];
From custom cell's class doesn't do anything.
How to change cell's state to showing delete confirmation without swipe?
i.e. after swipe gesture on a cell is recognized what is being called? I would like to call it manually.
That is a delegate method meaning you should not call it yourself as that is a part of the process handles by the tableView class.
Instead you'll want to override the call class, prepare the method to show your button (or whatever you want to show) and animate other views trimming their frames. Doing that you'll understand the difference between the delegate and instance messages as you'll probably need to notify the tableView or it's delegate that your method is complete, the button is shown and other views are also animated.

loading different text in same view controller

Hi I have a quiz app that I am working on, and on my RootViewController I have two buttons with action methods, now when I press on one of the buttons I get my questionViewController and text is loaded into specific fields, I do this by using the viewDidLoad method. When I go back to the RootViewController and click on a different button I want to show the same questionViewController but with different text, how can I go about doing this?
I just finished a project with similar requirement. One way to do this is to use static variable and class method in your questionViewController class.
You could implement viewDidAppear: on your questionViewController, and set the text there instead of viewDidLoad.
You could also implement a method on questionViewController, that updated the text fields, and call this method from the RootViewController.