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
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
Related
I am trying to run a simple button that you click. But when I run the simulator, the app launches, and then the simulator stops and an error pops up saying "Thread 1: Signal SIGABRT". I am completely new to Xcode. Could someone please help me?
I tried the linking and I did some research but nothing worked.
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
#IBAction func Button(_ sender: UIButton) {
print("Hello World!"
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
I want it to print "Hello World", but that isn't happening.
It looks like the outlets you created are not connected to your Storyboard subviews anymore. You can just check it out doing right-click on you button and seeing if your #IBAction is still there.
You can try out few of these points:
First check your #IBAction i.e your button action is connected to your view controller in main.storyboard
Then put a breakpoint in the action function and check if it is executing or not
Look at the connection by right click on outlets connection and see if its showing a warning yellow sign if showing and put a right connection.
- For more information about : USE OF BREAKPOINTS
Regarding Breakpoints see these screenshots
it seems to be the same error and conditions as this unanswered SO question, but I have more to add (its really easy to replicate)
Create a new project in the latest Xcode
iOS App with WatchKit App
Go to the WatchKit App > Interface.storyboard and put a single button on the Interface Controller Scene > Interface Controller
Go to WatchKit Extension > InterfaceController.swift and add a new member
#IBOutlet var scheduleMeetingButton: WKInterfaceButton!
and method
#IBAction func scheduleMeeting(_ sender: Any) { }
then go back to Interface.storyboard and link both of these to the button
launch the app (on the watch simulator)
than click the button and you will get this exec error
What is causing this error?
From looking at your code i would suggest updating the action function from sender: any to sender: wkinterfacebutton hope this helps!
func checkForRecipes(noRecords: Bool) {
//segue to addNewRecipe page
if noRecords == true{
print("Can't Find any Recipes!")
self.performSegue(withIdentifier: "ToAddNewRecipeVC", sender: self)
}else{
print("error, noRecords not equal to zero")
}
I am able to segue successfully via the storyboard but want to do so programmatically based on information returned from a delegate.
Upon running the app, the information from the delegate is successfully sent to the function "checkForRecipes" -i.e "noRecords" returns TRUE, but for some reason, the below line of code within that function does not seem to execute (and no errors are thrown):
self.performSegue(withIdentifier: "ToAddNewRecipeVC", sender: self)
The app starts up but stops at the main screen, whereas it should segue to the "AddNewRecipe" view controller.
The segue itself definitely has a segue ID of "ToAddNewRecipeVC". I have also tried dispatching to the main queue (to no avail) based on the following thread.
I'm stumped - what's going wrong here?
OK, it looks as though I have solved the problem. I embedded the main view controller into a navigation controller and now everything works as intended. I tried this same tactic earlier and it kept throwing up errors. grrr!
Anyway - thank you to all for the input!
I am trying to make a reset button for my app that will reset the UI to the original state. I have made a UIButton and linked it to the ViewController, but I have no idea where to go from here. I tried using the following code:
#IBAction func resetToOriginalState(sender: UIButton) {
self.resetToOriginalState (sender: UIButton)
}
It gave me the following error:
Editor placeholder in source file
Sorry if there may be an obvious answer, but I am very new to Swift and Xcode.
Is there any other way to create a reset button?
The error:
Editor placeholder in source file
Is because you are calling a function with the UIButton Class name instead of the actual button.
#IBAction func resetToOriginalState(sender: UIButton {
// this line is wrong, you shouldn't have UIButton in here
self.resetToOriginalState (sender: UIButton)
// the line should read
self.resetToOriginalState (sender: sender)
}
This way, you are passing the actual button into the function that was passed to resetToOriginalState
Seems you have too IBAction for the same button, check how many time you have #IBAction func resetToOriginalState(sender: UIButton) in your code and remove the references from the references Interface list to clean it, should there be only one :
It depends what is in the scene and what do you need to reload. As far is I know you can't really segue a ViewController to itself, but here are few options:
Try to add loadView() when the button is pressed
Duplicate the view controller, and segue between the two. (might be risky and create more work)
Reset your variables to their initial state when the button is pressed
You should give us more detail because this is implementation specific.
Nevertheless, it's not very clean, but depending on the architecture of your code, you might be able to generate a new instance of your view controller, destroy the current one, and present the new one.
I am currently trying to segue to a different view controller when a button is pressed. The button's action method is called correctly, but when it calls the perform segue with identifier it crashes the app and says "terminating with uncaught exception of type NSException". I have the segue identifier as "switchToMap". I segue to the same page from a different place in the app as well, but that seems to work just fine. Does anyone have any ideas?
func mapButtonPressed (sender: UIButton) {
performSegueWithIdentifier("switchToMap", sender: sender)
}
The other place the map page is segued to looks like this. It is part of a switch statement.
case 2:
performSegueWithIdentifier("map", sender: indexPath.item)