Pull To Refresh Stack View
up vote
0
down vote
favorite
I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?
swift
add a comment |
up vote
0
down vote
favorite
I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?
swift
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?
swift
I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?
swift
swift
asked 2 days ago
J Dub
3811
3811
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago
add a comment |
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
You can't add a refresh control into a stack view for the purpose of refreshing the content.
The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:
UIRefreshControl
A standard control that can initiate the refreshing of a scroll view’s
contents.
UIRefreshControl
For this case I would encourage to let your grid to be as a UICollectionView
instead of stack view.
In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.
Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:
- Is completely static UICollectionView possible?
- How to create a static UICollectionView.
- How to use pull to refresh in Swift?
add a comment |
up vote
0
down vote
Your best option is to go with a UICollectionView
. Create a custom cell to you desired needs. After that you can add a refresh controller:
// Global variable
let pullToRefreshData = UIRefreshControl()
// Where you initialise the collectionView (eg. viewDidAppear())
collectionView.refreshControl = pullToRefreshData
pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)
// This will be called when you pull from top of the collectionView
@objc func refreshData() {
// Maybe you need to call a server API, stop the reloading animation when you have the data
pullToRefreshData.endRefreshing()
// Refresh the data from the collectionView
collectionView.reloadData()
}
If you only need to use your implementation, maybe you can provide a context.
New contributor
add a comment |
up vote
0
down vote
For this use case I'd suggest using UICollectionView
, which has build in support for UIRefreshControl
. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView
in UIScrollView
and set it's refreshControl
.
See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can't add a refresh control into a stack view for the purpose of refreshing the content.
The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:
UIRefreshControl
A standard control that can initiate the refreshing of a scroll view’s
contents.
UIRefreshControl
For this case I would encourage to let your grid to be as a UICollectionView
instead of stack view.
In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.
Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:
- Is completely static UICollectionView possible?
- How to create a static UICollectionView.
- How to use pull to refresh in Swift?
add a comment |
up vote
0
down vote
You can't add a refresh control into a stack view for the purpose of refreshing the content.
The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:
UIRefreshControl
A standard control that can initiate the refreshing of a scroll view’s
contents.
UIRefreshControl
For this case I would encourage to let your grid to be as a UICollectionView
instead of stack view.
In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.
Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:
- Is completely static UICollectionView possible?
- How to create a static UICollectionView.
- How to use pull to refresh in Swift?
add a comment |
up vote
0
down vote
up vote
0
down vote
You can't add a refresh control into a stack view for the purpose of refreshing the content.
The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:
UIRefreshControl
A standard control that can initiate the refreshing of a scroll view’s
contents.
UIRefreshControl
For this case I would encourage to let your grid to be as a UICollectionView
instead of stack view.
In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.
Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:
- Is completely static UICollectionView possible?
- How to create a static UICollectionView.
- How to use pull to refresh in Swift?
You can't add a refresh control into a stack view for the purpose of refreshing the content.
The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:
UIRefreshControl
A standard control that can initiate the refreshing of a scroll view’s
contents.
UIRefreshControl
For this case I would encourage to let your grid to be as a UICollectionView
instead of stack view.
In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.
Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:
- Is completely static UICollectionView possible?
- How to create a static UICollectionView.
- How to use pull to refresh in Swift?
edited 2 days ago
answered 2 days ago
Ahmad F
15.4k94079
15.4k94079
add a comment |
add a comment |
up vote
0
down vote
Your best option is to go with a UICollectionView
. Create a custom cell to you desired needs. After that you can add a refresh controller:
// Global variable
let pullToRefreshData = UIRefreshControl()
// Where you initialise the collectionView (eg. viewDidAppear())
collectionView.refreshControl = pullToRefreshData
pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)
// This will be called when you pull from top of the collectionView
@objc func refreshData() {
// Maybe you need to call a server API, stop the reloading animation when you have the data
pullToRefreshData.endRefreshing()
// Refresh the data from the collectionView
collectionView.reloadData()
}
If you only need to use your implementation, maybe you can provide a context.
New contributor
add a comment |
up vote
0
down vote
Your best option is to go with a UICollectionView
. Create a custom cell to you desired needs. After that you can add a refresh controller:
// Global variable
let pullToRefreshData = UIRefreshControl()
// Where you initialise the collectionView (eg. viewDidAppear())
collectionView.refreshControl = pullToRefreshData
pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)
// This will be called when you pull from top of the collectionView
@objc func refreshData() {
// Maybe you need to call a server API, stop the reloading animation when you have the data
pullToRefreshData.endRefreshing()
// Refresh the data from the collectionView
collectionView.reloadData()
}
If you only need to use your implementation, maybe you can provide a context.
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
Your best option is to go with a UICollectionView
. Create a custom cell to you desired needs. After that you can add a refresh controller:
// Global variable
let pullToRefreshData = UIRefreshControl()
// Where you initialise the collectionView (eg. viewDidAppear())
collectionView.refreshControl = pullToRefreshData
pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)
// This will be called when you pull from top of the collectionView
@objc func refreshData() {
// Maybe you need to call a server API, stop the reloading animation when you have the data
pullToRefreshData.endRefreshing()
// Refresh the data from the collectionView
collectionView.reloadData()
}
If you only need to use your implementation, maybe you can provide a context.
New contributor
Your best option is to go with a UICollectionView
. Create a custom cell to you desired needs. After that you can add a refresh controller:
// Global variable
let pullToRefreshData = UIRefreshControl()
// Where you initialise the collectionView (eg. viewDidAppear())
collectionView.refreshControl = pullToRefreshData
pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)
// This will be called when you pull from top of the collectionView
@objc func refreshData() {
// Maybe you need to call a server API, stop the reloading animation when you have the data
pullToRefreshData.endRefreshing()
// Refresh the data from the collectionView
collectionView.reloadData()
}
If you only need to use your implementation, maybe you can provide a context.
New contributor
edited 2 days ago
Ahmad F
15.4k94079
15.4k94079
New contributor
answered 2 days ago
Deryck Lucian
715
715
New contributor
New contributor
add a comment |
add a comment |
up vote
0
down vote
For this use case I'd suggest using UICollectionView
, which has build in support for UIRefreshControl
. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView
in UIScrollView
and set it's refreshControl
.
See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol
add a comment |
up vote
0
down vote
For this use case I'd suggest using UICollectionView
, which has build in support for UIRefreshControl
. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView
in UIScrollView
and set it's refreshControl
.
See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol
add a comment |
up vote
0
down vote
up vote
0
down vote
For this use case I'd suggest using UICollectionView
, which has build in support for UIRefreshControl
. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView
in UIScrollView
and set it's refreshControl
.
See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol
For this use case I'd suggest using UICollectionView
, which has build in support for UIRefreshControl
. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView
in UIScrollView
and set it's refreshControl
.
See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol
answered yesterday
Radek
168
168
add a comment |
add a comment |
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%2f53365860%2fpull-to-refresh-stack-view%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
can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago