Scott Kilbourn
Scott Kilbourn

Reputation: 1586

Xcode Issue Adding Action

I'm working on a UI. When I want to add an action, I drag from the control to the code in the assistant editor. When the action is created, the code is inserted in to the middle of other functions, causing errors. This has been happening more and ore frequently. I even updated Xcode to the latest (7.3.1), to try and fix it. Here's an example of what happens:

override func viewDidLoad() {
    super.viewDidLoad()
    @IBAction func doneClicked(sender: AnyObject) {
    }

    //self.navigationItem.setHidesBackButton(true, animated: false)
}

You can see that the doneClicked Action is inserted in to the middle of viewDidLoad. The only way to fix it is to cut the code out of the middle of viewDidLoad, paste it lower, and then reconnect the action to the control.

It's getting really annoying. Is there any way to fix it or is there a better way to create the actions without doing it this way?

Upvotes: 1

Views: 63

Answers (2)

mshrestha
mshrestha

Reputation: 706

I think this is an Xcode bug because I have had similar problem too. After selecting Assistant Editor, you can fix this by selecting your file from automatic menu. This is what fixed it for me. You can refer the screenshot below. enter image description here

Upvotes: 2

Iyyappan Ravi
Iyyappan Ravi

Reputation: 3245

The viewDidLoad method is initially load the ViewController,if your doneClicked is method, you will set the method in out of the viewDidLoad, for example see below code,

if you want call the doneClicked method, just call this way,

override func viewDidLoad() {
    super.viewDidLoad()

    self.doneClicked("")        
}

@IBAction func doneClicked(sender: AnyObject) {
     // put your code
}

hope its helpful

Upvotes: 0

Related Questions