How to get Cell title from external data source for UICollectionView









up vote
0
down vote

favorite












I currently have a view where I display a collectionView with some categories. I followed this post to get my collectionView to properly load display data. I got that working just fine.



My issue is that now I need to be able to get the text from whichever cell the user selects to use within my search bar.



My current code:



class SearchViewController: ButtonBarPagerTabStripViewController, UISearchBarDelegate

let headerId = "sectionHeader"
let categoriesId = "categoriesId"

lazy var searchBar: UISearchBar =
let sb = UISearchBar()
sb.placeholder = "Search businesses or coupons"
sb.barTintColor = .gray
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.mainWhite()
sb.delegate = self
return sb
()

lazy var searchCategriesView: UICollectionView =
let layout = UICollectionViewFlowLayout()
layout.headerReferenceSize = CGSize(width: view.frame.width, height: 75)
layout.itemSize = CGSize(width: view.frame.width, height: 50)
layout.minimumInteritemSpacing = 1
layout.minimumLineSpacing = 1
layout.scrollDirection = .vertical
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.mainWhite()
cv.translatesAutoresizingMaskIntoConstraints = false
return cv
()

override func viewDidLoad()
super.viewDidLoad()
view.backgroundColor = .white

categoriesDataSource = SearchCategories()
searchCategriesView.dataSource = categoriesDataSource

searchCategriesView.register(SearchCategoriesCell.self, forCellWithReuseIdentifier: categoriesId)
searchCategriesView.register(SectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerId)


//EXCLUDED VIEW SETUP CODE FOR BREVITY



And as per the link mentioned above, I set up my data source in another file like this:



class SearchCategories: NSObject 
let categories = ["Apparel & Clothing", "Arts & Crafts", "Automotive",
"Baby", "Bars & Lounges", "Beauty", "Books",
"Entertainment",
"Family & Children", "Furniture",
"Grocery",
"Health", "Home & Garden", "Home improvement",
"Pets", "Pizza",
"Restaurants",
"Sporting Goods"]

let headerId = "sectionHeader"
let categoriesId = "categoriesId"

override init()




extension SearchCategories: UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
return categories.count


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
cell.label.text = categories[indexPath.item]
return cell


func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

let sectionHeaderView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath) as! SectionHeaderView

if indexPath.section == 0
sectionHeaderView.categoryTitleLabel.text = "Search Categories"

return sectionHeaderView


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
//NEED TO PASS THIS DATA BACK TO SEARCHVIEWCONTROLLER




How do I now get the cell text back in the SearchViewController whenever a user clicks on a collectionView cell?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I currently have a view where I display a collectionView with some categories. I followed this post to get my collectionView to properly load display data. I got that working just fine.



    My issue is that now I need to be able to get the text from whichever cell the user selects to use within my search bar.



    My current code:



    class SearchViewController: ButtonBarPagerTabStripViewController, UISearchBarDelegate

    let headerId = "sectionHeader"
    let categoriesId = "categoriesId"

    lazy var searchBar: UISearchBar =
    let sb = UISearchBar()
    sb.placeholder = "Search businesses or coupons"
    sb.barTintColor = .gray
    UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.mainWhite()
    sb.delegate = self
    return sb
    ()

    lazy var searchCategriesView: UICollectionView =
    let layout = UICollectionViewFlowLayout()
    layout.headerReferenceSize = CGSize(width: view.frame.width, height: 75)
    layout.itemSize = CGSize(width: view.frame.width, height: 50)
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 1
    layout.scrollDirection = .vertical
    let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
    cv.backgroundColor = UIColor.mainWhite()
    cv.translatesAutoresizingMaskIntoConstraints = false
    return cv
    ()

    override func viewDidLoad()
    super.viewDidLoad()
    view.backgroundColor = .white

    categoriesDataSource = SearchCategories()
    searchCategriesView.dataSource = categoriesDataSource

    searchCategriesView.register(SearchCategoriesCell.self, forCellWithReuseIdentifier: categoriesId)
    searchCategriesView.register(SectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerId)


    //EXCLUDED VIEW SETUP CODE FOR BREVITY



    And as per the link mentioned above, I set up my data source in another file like this:



    class SearchCategories: NSObject 
    let categories = ["Apparel & Clothing", "Arts & Crafts", "Automotive",
    "Baby", "Bars & Lounges", "Beauty", "Books",
    "Entertainment",
    "Family & Children", "Furniture",
    "Grocery",
    "Health", "Home & Garden", "Home improvement",
    "Pets", "Pizza",
    "Restaurants",
    "Sporting Goods"]

    let headerId = "sectionHeader"
    let categoriesId = "categoriesId"

    override init()




    extension SearchCategories: UICollectionViewDataSource
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    return categories.count


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
    cell.label.text = categories[indexPath.item]
    return cell


    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

    let sectionHeaderView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath) as! SectionHeaderView

    if indexPath.section == 0
    sectionHeaderView.categoryTitleLabel.text = "Search Categories"

    return sectionHeaderView


    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
    //NEED TO PASS THIS DATA BACK TO SEARCHVIEWCONTROLLER




    How do I now get the cell text back in the SearchViewController whenever a user clicks on a collectionView cell?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I currently have a view where I display a collectionView with some categories. I followed this post to get my collectionView to properly load display data. I got that working just fine.



      My issue is that now I need to be able to get the text from whichever cell the user selects to use within my search bar.



      My current code:



      class SearchViewController: ButtonBarPagerTabStripViewController, UISearchBarDelegate

      let headerId = "sectionHeader"
      let categoriesId = "categoriesId"

      lazy var searchBar: UISearchBar =
      let sb = UISearchBar()
      sb.placeholder = "Search businesses or coupons"
      sb.barTintColor = .gray
      UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.mainWhite()
      sb.delegate = self
      return sb
      ()

      lazy var searchCategriesView: UICollectionView =
      let layout = UICollectionViewFlowLayout()
      layout.headerReferenceSize = CGSize(width: view.frame.width, height: 75)
      layout.itemSize = CGSize(width: view.frame.width, height: 50)
      layout.minimumInteritemSpacing = 1
      layout.minimumLineSpacing = 1
      layout.scrollDirection = .vertical
      let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
      cv.backgroundColor = UIColor.mainWhite()
      cv.translatesAutoresizingMaskIntoConstraints = false
      return cv
      ()

      override func viewDidLoad()
      super.viewDidLoad()
      view.backgroundColor = .white

      categoriesDataSource = SearchCategories()
      searchCategriesView.dataSource = categoriesDataSource

      searchCategriesView.register(SearchCategoriesCell.self, forCellWithReuseIdentifier: categoriesId)
      searchCategriesView.register(SectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerId)


      //EXCLUDED VIEW SETUP CODE FOR BREVITY



      And as per the link mentioned above, I set up my data source in another file like this:



      class SearchCategories: NSObject 
      let categories = ["Apparel & Clothing", "Arts & Crafts", "Automotive",
      "Baby", "Bars & Lounges", "Beauty", "Books",
      "Entertainment",
      "Family & Children", "Furniture",
      "Grocery",
      "Health", "Home & Garden", "Home improvement",
      "Pets", "Pizza",
      "Restaurants",
      "Sporting Goods"]

      let headerId = "sectionHeader"
      let categoriesId = "categoriesId"

      override init()




      extension SearchCategories: UICollectionViewDataSource
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
      return categories.count


      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
      cell.label.text = categories[indexPath.item]
      return cell


      func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

      let sectionHeaderView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath) as! SectionHeaderView

      if indexPath.section == 0
      sectionHeaderView.categoryTitleLabel.text = "Search Categories"

      return sectionHeaderView


      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
      //NEED TO PASS THIS DATA BACK TO SEARCHVIEWCONTROLLER




      How do I now get the cell text back in the SearchViewController whenever a user clicks on a collectionView cell?










      share|improve this question













      I currently have a view where I display a collectionView with some categories. I followed this post to get my collectionView to properly load display data. I got that working just fine.



      My issue is that now I need to be able to get the text from whichever cell the user selects to use within my search bar.



      My current code:



      class SearchViewController: ButtonBarPagerTabStripViewController, UISearchBarDelegate

      let headerId = "sectionHeader"
      let categoriesId = "categoriesId"

      lazy var searchBar: UISearchBar =
      let sb = UISearchBar()
      sb.placeholder = "Search businesses or coupons"
      sb.barTintColor = .gray
      UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.mainWhite()
      sb.delegate = self
      return sb
      ()

      lazy var searchCategriesView: UICollectionView =
      let layout = UICollectionViewFlowLayout()
      layout.headerReferenceSize = CGSize(width: view.frame.width, height: 75)
      layout.itemSize = CGSize(width: view.frame.width, height: 50)
      layout.minimumInteritemSpacing = 1
      layout.minimumLineSpacing = 1
      layout.scrollDirection = .vertical
      let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
      cv.backgroundColor = UIColor.mainWhite()
      cv.translatesAutoresizingMaskIntoConstraints = false
      return cv
      ()

      override func viewDidLoad()
      super.viewDidLoad()
      view.backgroundColor = .white

      categoriesDataSource = SearchCategories()
      searchCategriesView.dataSource = categoriesDataSource

      searchCategriesView.register(SearchCategoriesCell.self, forCellWithReuseIdentifier: categoriesId)
      searchCategriesView.register(SectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerId)


      //EXCLUDED VIEW SETUP CODE FOR BREVITY



      And as per the link mentioned above, I set up my data source in another file like this:



      class SearchCategories: NSObject 
      let categories = ["Apparel & Clothing", "Arts & Crafts", "Automotive",
      "Baby", "Bars & Lounges", "Beauty", "Books",
      "Entertainment",
      "Family & Children", "Furniture",
      "Grocery",
      "Health", "Home & Garden", "Home improvement",
      "Pets", "Pizza",
      "Restaurants",
      "Sporting Goods"]

      let headerId = "sectionHeader"
      let categoriesId = "categoriesId"

      override init()




      extension SearchCategories: UICollectionViewDataSource
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
      return categories.count


      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
      cell.label.text = categories[indexPath.item]
      return cell


      func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

      let sectionHeaderView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath) as! SectionHeaderView

      if indexPath.section == 0
      sectionHeaderView.categoryTitleLabel.text = "Search Categories"

      return sectionHeaderView


      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: categoriesId, for: indexPath) as! SearchCategoriesCell
      //NEED TO PASS THIS DATA BACK TO SEARCHVIEWCONTROLLER




      How do I now get the cell text back in the SearchViewController whenever a user clicks on a collectionView cell?







      ios swift uicollectionview






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 23:10









      mufc

      1131723




      1131723






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Suppose you will hold the text in this function inside SearchViewController



          func send(_ res:String)
          print(res)



          1- Add a var inside



          class SearchCategories: NSObject {

          weak var delegate:SearchViewController?


          2- Set the delegate



          categoriesDataSource = SearchCategories()
          categoriesDataSource.delegate = self


          3- Send the clicked text



          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
          let sendedText = categories[indexPath.item]
          delegate?.send(sendedText)



          Edit: You need to add



          searchCategriesView.delegate = categoriesDataSource


          in viewDidLoad also you can do



          searchCategriesView.delegate = self


          and implement the didSelectItemAt inside SearchViewController






          share|improve this answer






















          • Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
            – mufc
            Nov 11 at 23:32










          • @mufc see last edit statement
            – Sh_Khan
            Nov 11 at 23:35










          • Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
            – Sh_Khan
            Nov 11 at 23:40











          • To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
            – mufc
            Nov 11 at 23:43










          • yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
            – Sh_Khan
            Nov 11 at 23:46










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254177%2fhow-to-get-cell-title-from-external-data-source-for-uicollectionview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          Suppose you will hold the text in this function inside SearchViewController



          func send(_ res:String)
          print(res)



          1- Add a var inside



          class SearchCategories: NSObject {

          weak var delegate:SearchViewController?


          2- Set the delegate



          categoriesDataSource = SearchCategories()
          categoriesDataSource.delegate = self


          3- Send the clicked text



          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
          let sendedText = categories[indexPath.item]
          delegate?.send(sendedText)



          Edit: You need to add



          searchCategriesView.delegate = categoriesDataSource


          in viewDidLoad also you can do



          searchCategriesView.delegate = self


          and implement the didSelectItemAt inside SearchViewController






          share|improve this answer






















          • Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
            – mufc
            Nov 11 at 23:32










          • @mufc see last edit statement
            – Sh_Khan
            Nov 11 at 23:35










          • Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
            – Sh_Khan
            Nov 11 at 23:40











          • To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
            – mufc
            Nov 11 at 23:43










          • yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
            – Sh_Khan
            Nov 11 at 23:46














          up vote
          0
          down vote



          accepted










          Suppose you will hold the text in this function inside SearchViewController



          func send(_ res:String)
          print(res)



          1- Add a var inside



          class SearchCategories: NSObject {

          weak var delegate:SearchViewController?


          2- Set the delegate



          categoriesDataSource = SearchCategories()
          categoriesDataSource.delegate = self


          3- Send the clicked text



          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
          let sendedText = categories[indexPath.item]
          delegate?.send(sendedText)



          Edit: You need to add



          searchCategriesView.delegate = categoriesDataSource


          in viewDidLoad also you can do



          searchCategriesView.delegate = self


          and implement the didSelectItemAt inside SearchViewController






          share|improve this answer






















          • Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
            – mufc
            Nov 11 at 23:32










          • @mufc see last edit statement
            – Sh_Khan
            Nov 11 at 23:35










          • Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
            – Sh_Khan
            Nov 11 at 23:40











          • To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
            – mufc
            Nov 11 at 23:43










          • yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
            – Sh_Khan
            Nov 11 at 23:46












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Suppose you will hold the text in this function inside SearchViewController



          func send(_ res:String)
          print(res)



          1- Add a var inside



          class SearchCategories: NSObject {

          weak var delegate:SearchViewController?


          2- Set the delegate



          categoriesDataSource = SearchCategories()
          categoriesDataSource.delegate = self


          3- Send the clicked text



          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
          let sendedText = categories[indexPath.item]
          delegate?.send(sendedText)



          Edit: You need to add



          searchCategriesView.delegate = categoriesDataSource


          in viewDidLoad also you can do



          searchCategriesView.delegate = self


          and implement the didSelectItemAt inside SearchViewController






          share|improve this answer














          Suppose you will hold the text in this function inside SearchViewController



          func send(_ res:String)
          print(res)



          1- Add a var inside



          class SearchCategories: NSObject {

          weak var delegate:SearchViewController?


          2- Set the delegate



          categoriesDataSource = SearchCategories()
          categoriesDataSource.delegate = self


          3- Send the clicked text



          func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
          let sendedText = categories[indexPath.item]
          delegate?.send(sendedText)



          Edit: You need to add



          searchCategriesView.delegate = categoriesDataSource


          in viewDidLoad also you can do



          searchCategriesView.delegate = self


          and implement the didSelectItemAt inside SearchViewController







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 23:35

























          answered Nov 11 at 23:23









          Sh_Khan

          37.2k51125




          37.2k51125











          • Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
            – mufc
            Nov 11 at 23:32










          • @mufc see last edit statement
            – Sh_Khan
            Nov 11 at 23:35










          • Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
            – Sh_Khan
            Nov 11 at 23:40











          • To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
            – mufc
            Nov 11 at 23:43










          • yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
            – Sh_Khan
            Nov 11 at 23:46
















          • Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
            – mufc
            Nov 11 at 23:32










          • @mufc see last edit statement
            – Sh_Khan
            Nov 11 at 23:35










          • Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
            – Sh_Khan
            Nov 11 at 23:40











          • To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
            – mufc
            Nov 11 at 23:43










          • yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
            – Sh_Khan
            Nov 11 at 23:46















          Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
          – mufc
          Nov 11 at 23:32




          Hi @Sh_Khan thanks for your quick response. This however isn't working. I implemented it exactly as you've shown and the cellForItemAt at method isn't even called. I put a breakpoint there and its not triggered. Is something missing?
          – mufc
          Nov 11 at 23:32












          @mufc see last edit statement
          – Sh_Khan
          Nov 11 at 23:35




          @mufc see last edit statement
          – Sh_Khan
          Nov 11 at 23:35












          Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
          – Sh_Khan
          Nov 11 at 23:40





          Don't forget to make categoriesDataSource here categoriesDataSource = SearchCategories() an instance variable
          – Sh_Khan
          Nov 11 at 23:40













          To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
          – mufc
          Nov 11 at 23:43




          To make searchCategoriesView.delegate = self I also had to make sure to do extension SearchCategories: UICollectionViewDelegate func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) let sendedText = categories[indexPath.item] delegate?.send(sendedText)
          – mufc
          Nov 11 at 23:43












          yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
          – Sh_Khan
          Nov 11 at 23:46




          yes implement didSelectItemAt there and leave the dataSource inside SearchCategories
          – Sh_Khan
          Nov 11 at 23:46

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254177%2fhow-to-get-cell-title-from-external-data-source-for-uicollectionview%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands