How do I perform a push segue from an imagePickerController? - ios

I've wired up a next button that sits on top of an imageView. My imagepicker sets the returned image to the imageView and I want to segue by pressing the IBAction. However when I press it, it doesn't perform the segue. I can see the button is being pressed, so I cant therefore understand why the segue isn't working. Does anyone know why?
#IBAction func nextPage(sender: AnyObject) {
self.performSegueWithIdentifier("showCaptionpage", sender: self)
}

Just drag imagePickercontroller to new Viewcontroller and select push. if you are using newer xcode version then push is deprecated. you can select show.

Related

What's wrong with my segue code in Swift?

I'm trying to segue into a 'settings' View Controller by clicking a button, and I'm assembling it via code but don't know what I'm doing wrong.
This is my button code:
#IBAction func settingsButton(_ sender: UIButton) {
self.performSegue(withIdentifier: "SettingsViewController", sender: self)
}
The View Controller is called 'Settings View Controller' (unsurprisingly). The app crashes whenever I press on it in my Simulator.
It'll probably be a simple thing, but any ideas what I'm doing wrong?
You must set your segue identifier whatever you want (for your question = SettingsViewController) from storyboard :
Hope it helps...

Go back to previous page using unwind segue

I wanted to just go back to my previous page
from Attendance in going to Leave and Leave back to Attendance
LeaveViewController.swift
#IBAction func LeaveAttendanceSequeConnect(_ sender: Any) {
performSegue(withIdentifier: "LeaveAttendanceSegue", sender: nil)
}
Attendance.swift
#IBAction func LeaveUnwindSeque(segue: UIStoryboardSegue){
}
and then on my Leave Scene
I have ctrl drag to Exit
Pressing the Back button in Leave wont go back to Attendance
The segue should work without needing another segue to leave the unwind. Try this:
1) Keep your original LeaveAttendanceSequeConnect (which should have been bound with ctrl drag from your view controller in story board over to your corresponding .swift file).
2)Get rid of the LeaveUnwindSeque code and unbind that rewind segue properly by deleting the segue (p.s. is segue with a "g" not seque). Now click on the segue connection of the LeaveAttendanceSequeConnect in the storyboard. Make sure the original navigation controller has attributes and looks the same on the storyboard like figures A) and then make sure your second segue has attributes/storyboard like figure B).
A attribute:
B attribute:
B storyboard:
A: storyboard:
The signature of the unwind is incorrect.
#IBAction func LeaveUnwindSeque(segue: UIStoryboardSegue){
}
replace with
#IBAction func LeaveUnwindSeque(_ segue: UIStoryboardSegue){
}

UIButton event doesn't get called when is pressed right away the view shows up

I have a button placed in the main view but when the user presses it right the view shows up, the button event doesn't get call so if the button is pressed again, it works fine. Does anyone know how to solve this problem?
Code:
#IBAction func goBack(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}

ViewController not displaying even though segue has been triggered

I have a TableViewController and I would like to trigger a segue within its navigation bar. I created the segue in the storyboard to my new ViewController. However if I click the bar button item, the view does not appear.
Instead the bar button item becomes inactive (greyed out) and the app freezes. There is no error message and the app does also not crash. The prepareForSegue method in my TableViewController also gets called
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
print("prepare for segue called")
print("destination view controller = \(segue.destinationViewController.description)")
}
I did the following things:
created a custom view Controller class for the second screen (in my storyboard and as a .swift file). I assigned the respective ViewController in the storyboard to my custom view controller in the Identity inspector
created an IBAction for a click event on the button and triggered
the segue programatically. The result remains the same.
prepareForSegue is called. The destionationViewController is correct
but does not show up. I removed this IBAction afterwards.
My destination view controller looks like this
class EnterUserDataViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("EnterUserDataViewController viewDidLoad called")
}
}
viewDidLoad never gets called even though the right segue has been triggered.
Can someone please give me a hint on why this happens?
You wouldn't happen to have a rogue breakpoint set somewhere would you?
If I put a breakpoint somewhere in the view loading cycle it recreates the exact symptoms you are describing.

Using a segue and an IBAction into one button

Is there any way to assign a segue as well as an IBAction to a button? Also would there be a different method of attempting this of transitioning from an MPMediaPickerController (e.i, the user would be on one view controller, choose a song, and appear in another)
The easiest way of doing that would be to place the segue into the IBAction. That way it will run both. To keep your code clean you could create a separate method for the segue and then call that method from inside the IBAction.
Example
#IBAction func buttonPressed(sender: UIButton) {
segue()
//do stuff
}
func segue() {
//run the transition
}
Hope that helps :)

Resources