Start and Stop indicatorView and put it in centre tableView in swift
I am using a spinner in bottom of tableView
to show the spinner when data is reloading.
var sneakers: [sneakerModel] =
I stored all my data in sneakers and returning the count on numberOfRowsInSection
method.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.sneakers.count
}
And now I am using willDisplay
method to show the spinner in bottom.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
if (indexPath.row == self.sneakers.count) {
self.tableView.tableFooterView?.isHidden = true
} else {
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = false
}
}
}
But it is not working. How can I stop spinner when no more data is loading. Please help?
Getting the data from api.
func getSneakerSearch() {
let param: [String:Any] = [ "search_term" : searchText ?? "","page": pageNo, "token": commonClass.sharedInstance.userToken ?? ""]
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
commonClass.sharedInstance.stopLoading()
guard let json = response.result.value as? [String:Any] else {return}
printD(json)
guard let status = json["status"] as? Int else {return}
printD(status)
if status == 1 {
guard let data = json["data"] as? [[String:Any]] else { return}
printD(data)
if self.pageNo == 0 {
self.sneakers.removeAll()
}
for item in data {
guard let description = item["description"] as? String else { return}
printD(description)
self.sneakers.append(sneakerModel(response: item))
}
self.didPageEnd = data.count < limitPerPage
}
DispatchQueue.main.async {
self.reloadData()
}
}
}
ios swift uitableview uiactivityindicatorview
|
show 3 more comments
I am using a spinner in bottom of tableView
to show the spinner when data is reloading.
var sneakers: [sneakerModel] =
I stored all my data in sneakers and returning the count on numberOfRowsInSection
method.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.sneakers.count
}
And now I am using willDisplay
method to show the spinner in bottom.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
if (indexPath.row == self.sneakers.count) {
self.tableView.tableFooterView?.isHidden = true
} else {
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = false
}
}
}
But it is not working. How can I stop spinner when no more data is loading. Please help?
Getting the data from api.
func getSneakerSearch() {
let param: [String:Any] = [ "search_term" : searchText ?? "","page": pageNo, "token": commonClass.sharedInstance.userToken ?? ""]
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
commonClass.sharedInstance.stopLoading()
guard let json = response.result.value as? [String:Any] else {return}
printD(json)
guard let status = json["status"] as? Int else {return}
printD(status)
if status == 1 {
guard let data = json["data"] as? [[String:Any]] else { return}
printD(data)
if self.pageNo == 0 {
self.sneakers.removeAll()
}
for item in data {
guard let description = item["description"] as? String else { return}
printD(description)
self.sneakers.append(sneakerModel(response: item))
}
self.didPageEnd = data.count < limitPerPage
}
DispatchQueue.main.async {
self.reloadData()
}
}
}
ios swift uitableview uiactivityindicatorview
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06
|
show 3 more comments
I am using a spinner in bottom of tableView
to show the spinner when data is reloading.
var sneakers: [sneakerModel] =
I stored all my data in sneakers and returning the count on numberOfRowsInSection
method.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.sneakers.count
}
And now I am using willDisplay
method to show the spinner in bottom.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
if (indexPath.row == self.sneakers.count) {
self.tableView.tableFooterView?.isHidden = true
} else {
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = false
}
}
}
But it is not working. How can I stop spinner when no more data is loading. Please help?
Getting the data from api.
func getSneakerSearch() {
let param: [String:Any] = [ "search_term" : searchText ?? "","page": pageNo, "token": commonClass.sharedInstance.userToken ?? ""]
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
commonClass.sharedInstance.stopLoading()
guard let json = response.result.value as? [String:Any] else {return}
printD(json)
guard let status = json["status"] as? Int else {return}
printD(status)
if status == 1 {
guard let data = json["data"] as? [[String:Any]] else { return}
printD(data)
if self.pageNo == 0 {
self.sneakers.removeAll()
}
for item in data {
guard let description = item["description"] as? String else { return}
printD(description)
self.sneakers.append(sneakerModel(response: item))
}
self.didPageEnd = data.count < limitPerPage
}
DispatchQueue.main.async {
self.reloadData()
}
}
}
ios swift uitableview uiactivityindicatorview
I am using a spinner in bottom of tableView
to show the spinner when data is reloading.
var sneakers: [sneakerModel] =
I stored all my data in sneakers and returning the count on numberOfRowsInSection
method.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.sneakers.count
}
And now I am using willDisplay
method to show the spinner in bottom.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
if (indexPath.row == self.sneakers.count) {
self.tableView.tableFooterView?.isHidden = true
} else {
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = false
}
}
}
But it is not working. How can I stop spinner when no more data is loading. Please help?
Getting the data from api.
func getSneakerSearch() {
let param: [String:Any] = [ "search_term" : searchText ?? "","page": pageNo, "token": commonClass.sharedInstance.userToken ?? ""]
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
commonClass.sharedInstance.stopLoading()
guard let json = response.result.value as? [String:Any] else {return}
printD(json)
guard let status = json["status"] as? Int else {return}
printD(status)
if status == 1 {
guard let data = json["data"] as? [[String:Any]] else { return}
printD(data)
if self.pageNo == 0 {
self.sneakers.removeAll()
}
for item in data {
guard let description = item["description"] as? String else { return}
printD(description)
self.sneakers.append(sneakerModel(response: item))
}
self.didPageEnd = data.count < limitPerPage
}
DispatchQueue.main.async {
self.reloadData()
}
}
}
ios swift uitableview uiactivityindicatorview
ios swift uitableview uiactivityindicatorview
edited Nov 23 '18 at 8:01
wings
asked Nov 23 '18 at 7:50
wingswings
1,113524
1,113524
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06
|
show 3 more comments
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06
|
show 3 more comments
2 Answers
2
active
oldest
votes
Create loadingview in viewdidload
override func viewDidLoad() {
super.viewDidLoad()
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = true
}
and update willDisplay cell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
}
Update getSnackerSearch func:
...
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}else{
self.tableView.tableFooterView?.isHidden = false
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
if self.pageNo == 0{
commonClass.sharedInstance.stopLoading()
}else{
self.tableView.tableFooterView?.isHidden = true
}
}
...
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
add a comment |
For center of you spinner to tableview you can follow these steps to do it. You don't need to provide height and width for spinner.
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
spinner.center=CGPointMake(self.tableView.center.x, self.tableView.center.y- topBarHeight);
getting error Use of unresolved identifierstatusBarHeight
andnavigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
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%2f53442594%2fstart-and-stop-indicatorview-and-put-it-in-centre-tableview-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create loadingview in viewdidload
override func viewDidLoad() {
super.viewDidLoad()
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = true
}
and update willDisplay cell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
}
Update getSnackerSearch func:
...
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}else{
self.tableView.tableFooterView?.isHidden = false
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
if self.pageNo == 0{
commonClass.sharedInstance.stopLoading()
}else{
self.tableView.tableFooterView?.isHidden = true
}
}
...
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
add a comment |
Create loadingview in viewdidload
override func viewDidLoad() {
super.viewDidLoad()
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = true
}
and update willDisplay cell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
}
Update getSnackerSearch func:
...
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}else{
self.tableView.tableFooterView?.isHidden = false
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
if self.pageNo == 0{
commonClass.sharedInstance.stopLoading()
}else{
self.tableView.tableFooterView?.isHidden = true
}
}
...
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
add a comment |
Create loadingview in viewdidload
override func viewDidLoad() {
super.viewDidLoad()
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = true
}
and update willDisplay cell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
}
Update getSnackerSearch func:
...
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}else{
self.tableView.tableFooterView?.isHidden = false
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
if self.pageNo == 0{
commonClass.sharedInstance.stopLoading()
}else{
self.tableView.tableFooterView?.isHidden = true
}
}
...
Create loadingview in viewdidload
override func viewDidLoad() {
super.viewDidLoad()
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(5), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
self.tableView.tableFooterView?.isHidden = true
}
and update willDisplay cell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.row == self.sneakers.count - 1 && !didPageEnd {
pageNo += 1
getSneakerSearch()
}
}
Update getSnackerSearch func:
...
if self.pageNo == 0{
commonClass.sharedInstance.startLoading()
}else{
self.tableView.tableFooterView?.isHidden = false
}
Alamofire.request(Constants.API.url("search"), method: .post, parameters: param, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
(response:DataResponse<Any>) in
if self.pageNo == 0{
commonClass.sharedInstance.stopLoading()
}else{
self.tableView.tableFooterView?.isHidden = true
}
}
...
answered Nov 23 '18 at 8:28
Nguyen HoanNguyen Hoan
1,157616
1,157616
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
add a comment |
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
Thanks for giving the answer I will try that but one more I want it in centre How can I achieve this ?
– wings
Nov 23 '18 at 9:00
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
var spinner: UIActivityIndicatorView! override func viewDidLoad() { self.spinner = UIActivityIndicatorView(.... and add spinner to self.view
– Nguyen Hoan
Nov 25 '18 at 7:15
add a comment |
For center of you spinner to tableview you can follow these steps to do it. You don't need to provide height and width for spinner.
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
spinner.center=CGPointMake(self.tableView.center.x, self.tableView.center.y- topBarHeight);
getting error Use of unresolved identifierstatusBarHeight
andnavigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
add a comment |
For center of you spinner to tableview you can follow these steps to do it. You don't need to provide height and width for spinner.
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
spinner.center=CGPointMake(self.tableView.center.x, self.tableView.center.y- topBarHeight);
getting error Use of unresolved identifierstatusBarHeight
andnavigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
add a comment |
For center of you spinner to tableview you can follow these steps to do it. You don't need to provide height and width for spinner.
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
spinner.center=CGPointMake(self.tableView.center.x, self.tableView.center.y- topBarHeight);
For center of you spinner to tableview you can follow these steps to do it. You don't need to provide height and width for spinner.
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.activityIndicatorViewStyle = .whiteLarge
spinner.color = .red
spinner.startAnimating()
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
spinner.center=CGPointMake(self.tableView.center.x, self.tableView.center.y- topBarHeight);
edited Nov 23 '18 at 17:26
answered Nov 23 '18 at 11:50
SachinVsSachinSachinVsSachin
5,03112735
5,03112735
getting error Use of unresolved identifierstatusBarHeight
andnavigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
add a comment |
getting error Use of unresolved identifierstatusBarHeight
andnavigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
getting error Use of unresolved identifier
statusBarHeight
and navigationHeight
– wings
Nov 23 '18 at 12:12
getting error Use of unresolved identifier
statusBarHeight
and navigationHeight
– wings
Nov 23 '18 at 12:12
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
@wings updated my answer
– SachinVsSachin
Nov 23 '18 at 17:26
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%2f53442594%2fstart-and-stop-indicatorview-and-put-it-in-centre-tableview-in-swift%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
Try self.tableView.tableFooterView?.isHidden = true whenever the data has loaded successfully from the API.
– Sateesh
Nov 23 '18 at 7:54
Where in calling api method ?
– wings
Nov 23 '18 at 7:56
Yes. In the API response methods inside.
– Sateesh
Nov 23 '18 at 7:59
Updated my question with calling api tell me where to call this method
– wings
Nov 23 '18 at 8:02
DispatchQueue.main.async { self.reloadData() self.yourTableView.tableFooterView?.isHidden = true }
– Sateesh
Nov 23 '18 at 8:06