Swift 4.2 Delegate and Protocol no working












2















I have UIViewController(profileViewController) in which there is collectionView, the collectionView have headerCell in which there is segmentedControl, when the segmentedControl value change, i want to tiger the delegate method but it not working, here is the code,
this is the class of collectioview headercell, and protocol.



import UIKit

// Protocol

protocol headerCellSegmentedDelegate {
func changeTabe(whichOne : String)
}

// HeaderCell Class

class HeaderProfileCollectionReusableView: UICollectionReusableView {
var headerDelegate : headerCellSegmentedDelegate?
@IBAction func changeValue(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
headerDelegate?.changeTabe(whichOne: "0")
}else{
headerDelegate?.changeTabe(whichOne: "1")
}
}
}


In the same UIViewController(profileViewController) which have the collectionView



    // profileViewController 
import UIKit
import SideMenu

class profileViewController: UIViewController {

//let headdercell = HeaderProfileCollectionReusableView()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// headdercell.headerDelegate = self //still not working with this too
setupSideMenu()
// Do any additional setup after loading the view.
}
}
extension profileViewController : headerCellSegmentedDelegate {
func changeTabe(whichOne: String) {
print("which tab " + whichOne)
}
}


i Try with protocol with class and weak, but still not working.










share|improve this question

























  • where did you defined the delegate in the ViewController.

    – Parth Dhorda
    Jan 1 at 6:01











  • can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

    – Jibran SiddiQui
    Jan 1 at 6:05











  • don't write your code in comment, use edit option and update your code.

    – Pratik Prajapati
    Jan 1 at 6:07











  • i have updated the code above

    – Jibran SiddiQui
    Jan 1 at 6:09











  • You need to confirm your headerDelegate refrences of your class (profileViewController).

    – Nimesh
    Jan 1 at 6:12
















2















I have UIViewController(profileViewController) in which there is collectionView, the collectionView have headerCell in which there is segmentedControl, when the segmentedControl value change, i want to tiger the delegate method but it not working, here is the code,
this is the class of collectioview headercell, and protocol.



import UIKit

// Protocol

protocol headerCellSegmentedDelegate {
func changeTabe(whichOne : String)
}

// HeaderCell Class

class HeaderProfileCollectionReusableView: UICollectionReusableView {
var headerDelegate : headerCellSegmentedDelegate?
@IBAction func changeValue(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
headerDelegate?.changeTabe(whichOne: "0")
}else{
headerDelegate?.changeTabe(whichOne: "1")
}
}
}


In the same UIViewController(profileViewController) which have the collectionView



    // profileViewController 
import UIKit
import SideMenu

class profileViewController: UIViewController {

//let headdercell = HeaderProfileCollectionReusableView()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// headdercell.headerDelegate = self //still not working with this too
setupSideMenu()
// Do any additional setup after loading the view.
}
}
extension profileViewController : headerCellSegmentedDelegate {
func changeTabe(whichOne: String) {
print("which tab " + whichOne)
}
}


i Try with protocol with class and weak, but still not working.










share|improve this question

























  • where did you defined the delegate in the ViewController.

    – Parth Dhorda
    Jan 1 at 6:01











  • can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

    – Jibran SiddiQui
    Jan 1 at 6:05











  • don't write your code in comment, use edit option and update your code.

    – Pratik Prajapati
    Jan 1 at 6:07











  • i have updated the code above

    – Jibran SiddiQui
    Jan 1 at 6:09











  • You need to confirm your headerDelegate refrences of your class (profileViewController).

    – Nimesh
    Jan 1 at 6:12














2












2








2








I have UIViewController(profileViewController) in which there is collectionView, the collectionView have headerCell in which there is segmentedControl, when the segmentedControl value change, i want to tiger the delegate method but it not working, here is the code,
this is the class of collectioview headercell, and protocol.



import UIKit

// Protocol

protocol headerCellSegmentedDelegate {
func changeTabe(whichOne : String)
}

// HeaderCell Class

class HeaderProfileCollectionReusableView: UICollectionReusableView {
var headerDelegate : headerCellSegmentedDelegate?
@IBAction func changeValue(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
headerDelegate?.changeTabe(whichOne: "0")
}else{
headerDelegate?.changeTabe(whichOne: "1")
}
}
}


In the same UIViewController(profileViewController) which have the collectionView



    // profileViewController 
import UIKit
import SideMenu

class profileViewController: UIViewController {

//let headdercell = HeaderProfileCollectionReusableView()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// headdercell.headerDelegate = self //still not working with this too
setupSideMenu()
// Do any additional setup after loading the view.
}
}
extension profileViewController : headerCellSegmentedDelegate {
func changeTabe(whichOne: String) {
print("which tab " + whichOne)
}
}


i Try with protocol with class and weak, but still not working.










share|improve this question
















I have UIViewController(profileViewController) in which there is collectionView, the collectionView have headerCell in which there is segmentedControl, when the segmentedControl value change, i want to tiger the delegate method but it not working, here is the code,
this is the class of collectioview headercell, and protocol.



import UIKit

// Protocol

protocol headerCellSegmentedDelegate {
func changeTabe(whichOne : String)
}

// HeaderCell Class

class HeaderProfileCollectionReusableView: UICollectionReusableView {
var headerDelegate : headerCellSegmentedDelegate?
@IBAction func changeValue(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
headerDelegate?.changeTabe(whichOne: "0")
}else{
headerDelegate?.changeTabe(whichOne: "1")
}
}
}


In the same UIViewController(profileViewController) which have the collectionView



    // profileViewController 
import UIKit
import SideMenu

class profileViewController: UIViewController {

//let headdercell = HeaderProfileCollectionReusableView()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// headdercell.headerDelegate = self //still not working with this too
setupSideMenu()
// Do any additional setup after loading the view.
}
}
extension profileViewController : headerCellSegmentedDelegate {
func changeTabe(whichOne: String) {
print("which tab " + whichOne)
}
}


i Try with protocol with class and weak, but still not working.







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 11:35









Kaushik Makwana

854422




854422










asked Jan 1 at 6:00









Jibran SiddiQuiJibran SiddiQui

739




739













  • where did you defined the delegate in the ViewController.

    – Parth Dhorda
    Jan 1 at 6:01











  • can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

    – Jibran SiddiQui
    Jan 1 at 6:05











  • don't write your code in comment, use edit option and update your code.

    – Pratik Prajapati
    Jan 1 at 6:07











  • i have updated the code above

    – Jibran SiddiQui
    Jan 1 at 6:09











  • You need to confirm your headerDelegate refrences of your class (profileViewController).

    – Nimesh
    Jan 1 at 6:12



















  • where did you defined the delegate in the ViewController.

    – Parth Dhorda
    Jan 1 at 6:01











  • can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

    – Jibran SiddiQui
    Jan 1 at 6:05











  • don't write your code in comment, use edit option and update your code.

    – Pratik Prajapati
    Jan 1 at 6:07











  • i have updated the code above

    – Jibran SiddiQui
    Jan 1 at 6:09











  • You need to confirm your headerDelegate refrences of your class (profileViewController).

    – Nimesh
    Jan 1 at 6:12

















where did you defined the delegate in the ViewController.

– Parth Dhorda
Jan 1 at 6:01





where did you defined the delegate in the ViewController.

– Parth Dhorda
Jan 1 at 6:01













can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

– Jibran SiddiQui
Jan 1 at 6:05





can you please again review the code? i extend the ViewController with protocol its delegate method, extension profileViewController : headerCellSegmentedDelegate { func changeTabe(whichOne: String) { print("which tab " + whichOne) } }

– Jibran SiddiQui
Jan 1 at 6:05













don't write your code in comment, use edit option and update your code.

– Pratik Prajapati
Jan 1 at 6:07





don't write your code in comment, use edit option and update your code.

– Pratik Prajapati
Jan 1 at 6:07













i have updated the code above

– Jibran SiddiQui
Jan 1 at 6:09





i have updated the code above

– Jibran SiddiQui
Jan 1 at 6:09













You need to confirm your headerDelegate refrences of your class (profileViewController).

– Nimesh
Jan 1 at 6:12





You need to confirm your headerDelegate refrences of your class (profileViewController).

– Nimesh
Jan 1 at 6:12












1 Answer
1






active

oldest

votes


















0














First of all your code



//let headdercell = HeaderProfileCollectionReusableView()


shouldn't be commented.



Second, after you uncomment that, assign headerDelegate value to self.



headdercell.headerDelegate = self





share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f53993337%2fswift-4-2-delegate-and-protocol-no-working%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









    0














    First of all your code



    //let headdercell = HeaderProfileCollectionReusableView()


    shouldn't be commented.



    Second, after you uncomment that, assign headerDelegate value to self.



    headdercell.headerDelegate = self





    share|improve this answer




























      0














      First of all your code



      //let headdercell = HeaderProfileCollectionReusableView()


      shouldn't be commented.



      Second, after you uncomment that, assign headerDelegate value to self.



      headdercell.headerDelegate = self





      share|improve this answer


























        0












        0








        0







        First of all your code



        //let headdercell = HeaderProfileCollectionReusableView()


        shouldn't be commented.



        Second, after you uncomment that, assign headerDelegate value to self.



        headdercell.headerDelegate = self





        share|improve this answer













        First of all your code



        //let headdercell = HeaderProfileCollectionReusableView()


        shouldn't be commented.



        Second, after you uncomment that, assign headerDelegate value to self.



        headdercell.headerDelegate = self






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 7:07









        rv7284rv7284

        780720




        780720
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993337%2fswift-4-2-delegate-and-protocol-no-working%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







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules