How to scroll to first cell, while swiping the last cell on CollectionView?
I'm working on a CollectionView with many cells in it. And what I am trying to do is:
- When the user is on the last cell of collectionView, and when the user swipes to see the next cell, I want this collectionView to restarts from the beginning. ( Basically, I need an endless loop )
Hope I could explain it correctly. Waiting for your solutions. Thank you.
ios swift uicollectionview uicollectionviewcell collectionview
add a comment |
I'm working on a CollectionView with many cells in it. And what I am trying to do is:
- When the user is on the last cell of collectionView, and when the user swipes to see the next cell, I want this collectionView to restarts from the beginning. ( Basically, I need an endless loop )
Hope I could explain it correctly. Waiting for your solutions. Thank you.
ios swift uicollectionview uicollectionviewcell collectionview
1
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47
add a comment |
I'm working on a CollectionView with many cells in it. And what I am trying to do is:
- When the user is on the last cell of collectionView, and when the user swipes to see the next cell, I want this collectionView to restarts from the beginning. ( Basically, I need an endless loop )
Hope I could explain it correctly. Waiting for your solutions. Thank you.
ios swift uicollectionview uicollectionviewcell collectionview
I'm working on a CollectionView with many cells in it. And what I am trying to do is:
- When the user is on the last cell of collectionView, and when the user swipes to see the next cell, I want this collectionView to restarts from the beginning. ( Basically, I need an endless loop )
Hope I could explain it correctly. Waiting for your solutions. Thank you.
ios swift uicollectionview uicollectionviewcell collectionview
ios swift uicollectionview uicollectionviewcell collectionview
asked Dec 29 '18 at 11:02
Ers TarErs Tar
487
487
1
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47
add a comment |
1
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47
1
1
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47
add a comment |
1 Answer
1
active
oldest
votes
Try this.
import UIKit
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate=self;
collectionView.dataSource=self;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
if indexpath.row==99{
self.btnScroll()
}
return cell
}
func btnScroll() {
collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: UICollectionView.ScrollPosition.top, animated:true)
}
}
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
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%2f53968933%2fhow-to-scroll-to-first-cell-while-swiping-the-last-cell-on-collectionview%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
Try this.
import UIKit
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate=self;
collectionView.dataSource=self;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
if indexpath.row==99{
self.btnScroll()
}
return cell
}
func btnScroll() {
collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: UICollectionView.ScrollPosition.top, animated:true)
}
}
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
add a comment |
Try this.
import UIKit
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate=self;
collectionView.dataSource=self;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
if indexpath.row==99{
self.btnScroll()
}
return cell
}
func btnScroll() {
collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: UICollectionView.ScrollPosition.top, animated:true)
}
}
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
add a comment |
Try this.
import UIKit
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate=self;
collectionView.dataSource=self;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
if indexpath.row==99{
self.btnScroll()
}
return cell
}
func btnScroll() {
collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: UICollectionView.ScrollPosition.top, animated:true)
}
}
Try this.
import UIKit
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate=self;
collectionView.dataSource=self;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
if indexpath.row==99{
self.btnScroll()
}
return cell
}
func btnScroll() {
collectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: UICollectionView.ScrollPosition.top, animated:true)
}
}
edited Dec 30 '18 at 14:01
answered Dec 29 '18 at 13:05
Sagar koyaniSagar koyani
1339
1339
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
add a comment |
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
unfortunately, this is scrolling to first item, what I need is showing the first item after the last one and continue to scroll like I have more contents in that collectionView
– Ers Tar
Jan 4 at 8:48
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%2f53968933%2fhow-to-scroll-to-first-cell-while-swiping-the-last-cell-on-collectionview%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
1
Look here How to implement horizontally infinite scrolling UICollectionView?
– Robert Dresler
Dec 29 '18 at 11:05
@Ers Tar have you find your answer from my answer?
– Sagar koyani
Jan 3 at 11:42
@Sagarkoyani yes, thank you so much. it was helpful!
– Ers Tar
Jan 4 at 8:47