UICollectionView didSelectedItemAt : first click on cell doesn't work
Like written in the title, the didSelectedItemAt is bugging, but that's a little more complicated than in the title, I explain :
I try to code an application wich is listing some stuffs. So I've got a ViewController with inside a TableView and a CollectionView. At the beggining the tableview's hidden is on false and the collectionview's one is on true. I've got a button on the navigation bar to switch CollectionView / TableView hidden true/false (I hope I'll be understandable with my bad english !). So the didSelectedRowAt is working well, but the didSelectedItemAt isn't. When I first click on a cell, nothing happen (on the screen at least), but the second click is working..... With the indexpath of the first click... I can't figure out why that's happening..
Does anyone knows why ?
Here is the some code of the app :
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print (dogs[indexPath.row].name)
let vc = storyboard?.instantiateViewController(withIdentifier: "DogDetailsView") as? DogDetailsView
vc?.nameSend = dogs[indexPath.row].name
vc?.infoSend = dogs[indexPath.row].info
self.navigationController?.pushViewController(vc!, animated: true)
}
Thank's you for helping :)
ios swift uicollectionview
add a comment |
Like written in the title, the didSelectedItemAt is bugging, but that's a little more complicated than in the title, I explain :
I try to code an application wich is listing some stuffs. So I've got a ViewController with inside a TableView and a CollectionView. At the beggining the tableview's hidden is on false and the collectionview's one is on true. I've got a button on the navigation bar to switch CollectionView / TableView hidden true/false (I hope I'll be understandable with my bad english !). So the didSelectedRowAt is working well, but the didSelectedItemAt isn't. When I first click on a cell, nothing happen (on the screen at least), but the second click is working..... With the indexpath of the first click... I can't figure out why that's happening..
Does anyone knows why ?
Here is the some code of the app :
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print (dogs[indexPath.row].name)
let vc = storyboard?.instantiateViewController(withIdentifier: "DogDetailsView") as? DogDetailsView
vc?.nameSend = dogs[indexPath.row].name
vc?.infoSend = dogs[indexPath.row].info
self.navigationController?.pushViewController(vc!, animated: true)
}
Thank's you for helping :)
ios swift uicollectionview
10
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43
add a comment |
Like written in the title, the didSelectedItemAt is bugging, but that's a little more complicated than in the title, I explain :
I try to code an application wich is listing some stuffs. So I've got a ViewController with inside a TableView and a CollectionView. At the beggining the tableview's hidden is on false and the collectionview's one is on true. I've got a button on the navigation bar to switch CollectionView / TableView hidden true/false (I hope I'll be understandable with my bad english !). So the didSelectedRowAt is working well, but the didSelectedItemAt isn't. When I first click on a cell, nothing happen (on the screen at least), but the second click is working..... With the indexpath of the first click... I can't figure out why that's happening..
Does anyone knows why ?
Here is the some code of the app :
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print (dogs[indexPath.row].name)
let vc = storyboard?.instantiateViewController(withIdentifier: "DogDetailsView") as? DogDetailsView
vc?.nameSend = dogs[indexPath.row].name
vc?.infoSend = dogs[indexPath.row].info
self.navigationController?.pushViewController(vc!, animated: true)
}
Thank's you for helping :)
ios swift uicollectionview
Like written in the title, the didSelectedItemAt is bugging, but that's a little more complicated than in the title, I explain :
I try to code an application wich is listing some stuffs. So I've got a ViewController with inside a TableView and a CollectionView. At the beggining the tableview's hidden is on false and the collectionview's one is on true. I've got a button on the navigation bar to switch CollectionView / TableView hidden true/false (I hope I'll be understandable with my bad english !). So the didSelectedRowAt is working well, but the didSelectedItemAt isn't. When I first click on a cell, nothing happen (on the screen at least), but the second click is working..... With the indexpath of the first click... I can't figure out why that's happening..
Does anyone knows why ?
Here is the some code of the app :
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print (dogs[indexPath.row].name)
let vc = storyboard?.instantiateViewController(withIdentifier: "DogDetailsView") as? DogDetailsView
vc?.nameSend = dogs[indexPath.row].name
vc?.infoSend = dogs[indexPath.row].info
self.navigationController?.pushViewController(vc!, animated: true)
}
Thank's you for helping :)
ios swift uicollectionview
ios swift uicollectionview
asked Nov 20 at 18:19
Asker
112
112
10
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43
add a comment |
10
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43
10
10
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43
add a comment |
1 Answer
1
active
oldest
votes
You are using wrong delegate method. Use following
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
The reason behind your didDeselect is working after the second tap is, you have turned on allowMultilpleSelection and whenever you tap first that cell its get selected, but you didn't implemented the correct delegate to hear that. when you tap once more, that cell is now deselected. That's why you are getting the callback in implemented method in such way.
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%2f53399162%2fuicollectionview-didselecteditemat-first-click-on-cell-doesnt-work%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
You are using wrong delegate method. Use following
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
The reason behind your didDeselect is working after the second tap is, you have turned on allowMultilpleSelection and whenever you tap first that cell its get selected, but you didn't implemented the correct delegate to hear that. when you tap once more, that cell is now deselected. That's why you are getting the callback in implemented method in such way.
add a comment |
You are using wrong delegate method. Use following
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
The reason behind your didDeselect is working after the second tap is, you have turned on allowMultilpleSelection and whenever you tap first that cell its get selected, but you didn't implemented the correct delegate to hear that. when you tap once more, that cell is now deselected. That's why you are getting the callback in implemented method in such way.
add a comment |
You are using wrong delegate method. Use following
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
The reason behind your didDeselect is working after the second tap is, you have turned on allowMultilpleSelection and whenever you tap first that cell its get selected, but you didn't implemented the correct delegate to hear that. when you tap once more, that cell is now deselected. That's why you are getting the callback in implemented method in such way.
You are using wrong delegate method. Use following
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
The reason behind your didDeselect is working after the second tap is, you have turned on allowMultilpleSelection and whenever you tap first that cell its get selected, but you didn't implemented the correct delegate to hear that. when you tap once more, that cell is now deselected. That's why you are getting the callback in implemented method in such way.
answered Nov 21 at 7:51
Ratul Sharker
2,69711526
2,69711526
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.
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.
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%2f53399162%2fuicollectionview-didselecteditemat-first-click-on-cell-doesnt-work%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
10
That's because you implemented didDeselectItemAt
– Martin R
Nov 20 at 18:20
Hmmm... right, what a shame to spend that time on this mistake, thank you !
– Asker
Nov 22 at 12:43