Swift 4.2 Delegate and Protocol no working
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
|
show 4 more comments
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
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, useedit
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
|
show 4 more comments
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
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
ios swift
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, useedit
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
|
show 4 more comments
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, useedit
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
|
show 4 more comments
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Jan 1 at 7:07
rv7284rv7284
780720
780720
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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