2

I am using Xcode 7. I wrote unwind function in view A. I want to return from view B to view A. When i drag my button with ctrl on exit, no any unwind function appears. When i right click on exit, it is empty. How can i resolve it? or can i set unwind programmatically?

Here is my unwind function:

@IBAction func unwindToProductList(sender: UIStoryboardSegue) {
    print("unwindToProductList called")
}

enter image description here

Edit:

I think i found the issue, but can't understand why xcode acts like that. At the beginning of my viewcontroller i have this code lines:

import UIKit

extension ProductListViewController: UISearchResultsUpdating {
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        filterContentForSearchText(searchController.searchBar.text!)
    }
}

class ProductListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
.....
}

when i comment my extension, exit see my unwind function, but if uncomment my extension, exit does not see my unwind function again, did i write extension at the wrong place?

Solution:

I fixed my issue by removing extension from the beginning of my code and implemented it in the view controller, after it Exit button start seeing my unwind function:

class ProductListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {

    func updateSearchResultsForSearchController(searchController: UISearchController) {
        filterContentForSearchText(searchController.searchBar.text!)
    }

    ....
}
kakajan
  • 2,614
  • 2
  • 22
  • 39
  • did you write in UIVIew or UIViewController class? – LC 웃 Feb 14 '16 at 17:46
  • http://stackoverflow.com/questions/35300192/unwind-segue-vs-popviewcontrolleranimated/35319786#35319786 please check out this – LC 웃 Feb 14 '16 at 17:47
  • What is the segue connection between view (controller) A and view (controller) B (_from_ A to B)? Compare with the similar detailed solution [described here](http://stackoverflow.com/a/35314768/4573247). – dfrib Feb 14 '16 at 17:52
  • @anishparajuli i wrote it in UIViewController and at the same time my class implements UITableViewDataSource, UITableViewDelegate – kakajan Feb 14 '16 at 19:18
  • @dfri segue connection from A to B is "Show (e.g Push)" – kakajan Feb 14 '16 at 19:20
  • the weird thing i detected is, when i write my unwind to another view controller exit detects it, but when i write my unwind in my A view controller, unfortunately exit does not detect it, i think my issue in A view controller. – kakajan Feb 14 '16 at 19:26
  • @dfri, i updated my question a little bit, please check it – kakajan Feb 14 '16 at 19:31
  • can you please share this test project? – LC 웃 Feb 15 '16 at 04:35

2 Answers2

2

I fixed my issue by removing extension from the beginning of my code and implemented it in the view controller, after it Exit button start seeing my unwind function:

class ProductListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {

    func updateSearchResultsForSearchController(searchController: UISearchController) {
        filterContentForSearchText(searchController.searchBar.text!)
    }

    ....
}
kakajan
  • 2,614
  • 2
  • 22
  • 39
0

Could it be that your class for view controller "A" in IB is not assigned to the corresponding UIViewController class you defined ? This would prevent the editor/compiler from seeing the IBAction because it won't find any IB view controller that links to your class.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
  • You probably already tried, but "Clean" and rebuild sometimes fixes that kind of issue for me – Alain T. Feb 14 '16 at 20:34
  • i tried it :), i also tried restarting Xcode too. For now I resolved my issue by removing extension and rewrite implementation of function `updateSearchResultsForSearchController` in my view controller – kakajan Feb 14 '16 at 20:44