IBOutlet button not working - Swift
IBOutlet button not working - Swift
I have searched for a similar question to this but cannot find it because mine is very obscure.
I am currently developing a social network app. All my code seems to be correct. However, there is the share button that is not working. I will attach the code here:
@IBOutlet weak var shareBtn: UIButton!
which is in one of my files to connect it up and:
@objc func toCreatePost (_ sender: AnyObject) {
performSegue(withIdentifier: "toCreatePost", sender: nil)
}
Before you ask, all of my segues are connected, the buttons are connected to the code and the identifier is correct.
I don't know if it could be an error in Xcode itself or my code, but the button clicks when it is run however it does not do anything. Help would be appreciated.
The error is that when the button is clicked it does not do anything and will not go to the next ViewController even though the code seems to be correct.
@IBAction func toCreatePost (_ sender: AnyObject) {
performSegue(withIdentifier: "toCreatePost", sender: nil)
}
Above is the code with an IBaction which I edited which now gives me a crash. The crash is a Thread 1: signal SIGABRT
Here is my main.storyboard

Does
toCreatePost get called (i.e. put a breakpoint or a print inside it)?– Grimxn
Jul 2 at 17:43
toCreatePost
print
do you have a
shouldPerformSegue or performSegue that makes it retrurn without performing the segue?– Daniel
Jul 2 at 17:44
shouldPerformSegue
performSegue
The toCreatePost is an identifier used in the storyboard where the shareBtn is connecting to the new screen
– Charlie Jones
Jul 2 at 17:50
@rmaddy I have changed it to a IBAction. Then reconnected this to the shareBtn however I am getting a crash when this is done. Any ideas?
– Charlie Jones
Jul 2 at 18:18
1 Answer
1
See this for view-based issues click here
It seems you have not added navigation controller before the view controller from where you have to perform segua action.
if your problem still not resolved try to push manualy without segua
I will upload a screenshot of my main.storyboard.
– Charlie Jones
Jul 2 at 19:04
Did you check by adding print method inside the action
– Sazid Iqabal
Jul 2 at 19:12
just checked, get a crash Thread 1: signal SIGABRT before it can print.
– Charlie Jones
Jul 2 at 20:05
Now check above link it is based on your problem
– Sazid Iqabal
Jul 2 at 20:14
same error still. Tried cleaning my project before. Here is what is in the terminal libc++abi.dylib: terminating with uncaught exception of type NSException
– Charlie Jones
Jul 2 at 20:26
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Put a breakpoint in the action. Does your app halt when the button is pressed? If not, there is a problem with your target/action pattern.
– the4kman
Jul 2 at 17:42