Domanda

I have a storyboard created with 2 views. ViewController1 and ViewController2. What I want to be able to do is after a user fills in specific fields and clicks the "Login" button on view1, is transition the user to view2.

I have the button successfully linked up to a method that executes when it is pressed I am just not sure how to do the transition.

È stato utile?

Soluzione

This is patterned off the standard IOS Utility template:

1) In your storyboard, set up a Modal segue from view controller 1 to 2. Do this by control dragging from the view controller 1 icon (icon on the right at the bottom of your view controller) to view controller 2. Select modal as the transition type and give this segue an identifier such as ShowViewController2.

2) In your implementation file for view controller 1, call this when the user presses Log In

self.performSegueWithIdentifier("ShowViewController2", sender:self)

Then implement prepareForSegue in viewController1 to set up viewController2:

def prepareForSegue(segue, sender:sender)
    # call setters to pass data to the second view controller

    # set up a delegate pointer so that you can get back to VC1
    segue.destinationViewController.delegate = self
end

Also, implement a method in view controller 1 to be called when view controller 2 is done

# Come back here when view controller 2 is done, for instance if the
# user logs off.
def view_controller_2_is_done(sender)
    self.dismissModalViewControllerAnimated(true)
end

For view controller 2, you'll want to set up a setter for delegate with

attr_accessor :delegate

When it is time to return to view controller 1 (ie when the user logs out), call:

@delegate.view_controller_2_is_done(self)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top