1

I've much the same problem as in this question but these solutions don't work. Currently running xcode 7.3.1.

I've a split view controller app, that modally presents a save record view controller. On the save VC, there are a save and cancel button that should (in both cases) unwind back to the master view.

Within the Master View Controller, I have the following code:

@IBAction func unwindToSegue (segue: UIStoryboardSegue) { }

BUT, there's a compiler error: Only instance methods can be declared @IBAction. There is the suggestion to delete @IBAction, but while this removes the error I can't connect to this action in the child VC.

With or without @IBAction in the unwind method, I get the same issue described in the referenced problem - dragging a line from my UIButton to the Exit button in Storyboard IB, does not show any action to connect with.

Community
  • 1
  • 1
DrWhat
  • 2,360
  • 5
  • 19
  • 33
  • Can you post more code like how you are defining unwindToSegue method in your class – Yuvrajsinh May 17 '16 at 14:15
  • To add to what @Yuvrajsinh said about how, can you also show where (i.e. in which VC)? – ppp May 17 '16 at 14:39
  • There's no actual code for the method so far. In a dummy (super simple project) I just have a print statement to show it is called. This works fine, but in my real project, there must be a setting or something that won't allow the exact same @IBAction to be defined and then found in IB. – DrWhat May 17 '16 at 14:41
  • Master VC has the IBAction in it. The Master VC is embedded in a nav controller with a bar button that presents modally a new record VC. The new record VC has a save button in it, which I want to unwind back to the Master VC. BUT, the save button does exactly what is shown in the referenced question - draws a line to exit, but exit does not allow selection; and if right clicked shows no presenting segues. – DrWhat May 17 '16 at 14:45

3 Answers3

1

You need to put the function inside the UIViewController.

class MasterViewController: UIViewController {
    @IBAction func unwindToSegue(segue: UIStoryboardSegue) { }
}
  • I was nesting this IBAction func within another function, and while this is OK for other functions, it does not appear ok for an IBAction. As per your answer, it begins to work again. Back to basics is always good. Thx. – DrWhat May 17 '16 at 15:14
1

I got this error simply when I had an extra parenthesis in my code... it was positioned before the IBAction method, so it essentially cut it off from being inside the UIViewController class, as Tomas suggests. So, check that all of your parenthesis are in place.

Azurespot
  • 3,066
  • 3
  • 45
  • 73
0

@IBAction is very picky with regard to syntax including white spaces between the string. for an example, nameA.txt ="" is not acceptable. you need to have equal white space contiguous to string such as nameA.text = ""