[Swift4]UIRefreshControl Indicator appear at different position












0















I am trying to make an iOS app, using Xcode 10.1 (10B61) and Swift4.



I have an issue about UIRefreshControl Indicator appearance, like the image below.



IssueImage
UIRefreshControl script is written in each TableViewController class (same code about refresh func).



class TableViewController1: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}




class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}


Anybody please give me some advise.



Thank you.










share|improve this question




















  • 1





    I guess you are missing to set the frame or offset for UIRefreshControl

    – Mukesh
    Nov 22 '18 at 6:18
















0















I am trying to make an iOS app, using Xcode 10.1 (10B61) and Swift4.



I have an issue about UIRefreshControl Indicator appearance, like the image below.



IssueImage
UIRefreshControl script is written in each TableViewController class (same code about refresh func).



class TableViewController1: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}




class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}


Anybody please give me some advise.



Thank you.










share|improve this question




















  • 1





    I guess you are missing to set the frame or offset for UIRefreshControl

    – Mukesh
    Nov 22 '18 at 6:18














0












0








0








I am trying to make an iOS app, using Xcode 10.1 (10B61) and Swift4.



I have an issue about UIRefreshControl Indicator appearance, like the image below.



IssueImage
UIRefreshControl script is written in each TableViewController class (same code about refresh func).



class TableViewController1: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}




class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}


Anybody please give me some advise.



Thank you.










share|improve this question
















I am trying to make an iOS app, using Xcode 10.1 (10B61) and Swift4.



I have an issue about UIRefreshControl Indicator appearance, like the image below.



IssueImage
UIRefreshControl script is written in each TableViewController class (same code about refresh func).



class TableViewController1: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}




class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
}


Anybody please give me some advise.



Thank you.







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:17









wvteijlingen

8,77912545




8,77912545










asked Nov 22 '18 at 5:54









himiyo3inhimiyo3in

132




132








  • 1





    I guess you are missing to set the frame or offset for UIRefreshControl

    – Mukesh
    Nov 22 '18 at 6:18














  • 1





    I guess you are missing to set the frame or offset for UIRefreshControl

    – Mukesh
    Nov 22 '18 at 6:18








1




1





I guess you are missing to set the frame or offset for UIRefreshControl

– Mukesh
Nov 22 '18 at 6:18





I guess you are missing to set the frame or offset for UIRefreshControl

– Mukesh
Nov 22 '18 at 6:18












3 Answers
3






active

oldest

votes


















2














This happens because of combination of things.




  1. You're using large headers for navigation controller. That makes TableViewController (actually any scrollable view) to put its refreshControl on navigation bar . This behaviour was introduced in iOS 11 https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles


  2. You're using two scrollable views and one of them binds to navigation bar and another is not. During debug I've found out that the first scrollable view in hierarchy attached its refreshControl to navigation bar.



So, that's means we can fix it by putting some fake or dummy scrollable view somewhere on the bottom of hierarchy in order to it binds its refreshControl to navigation bar first. Starting from iOS 11 any scrollable view may have refreshControl and its "binded" even if you don't declare it explicitly.



In your case you might just add UIScrollView before container in this way:




- View
-- Safe Area
-- UIScrollView (dummy)
-- ContainerView
---- TableView 1
---- TableView 2
...






share|improve this answer


























  • @iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

    – himiyo3in
    Nov 22 '18 at 8:37











  • @ilya ..Amazing solution along with description !!!

    – SachinVsSachin
    Nov 22 '18 at 9:30



















0














Try this--



class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
//Updated code.. this will fix it
self.tableView.addSubview(refreshControl)

}


Let us know .. is working ?






share|improve this answer
























  • tableviewcontroller already have refreshControl property.

    – Lal Krishna
    Nov 22 '18 at 6:36











  • but this time new allocations has happened.. so there I have doubt over to added view in tableView..

    – SachinVsSachin
    Nov 22 '18 at 6:38











  • @SachinVsSachin Thank you for your advise, but it's not working...

    – himiyo3in
    Nov 22 '18 at 8:31



















0














TableviewController 1



class TableViewController1: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
tableView1.addSubview(refreshControl) // Added Line

}


TableviewController 2



class TableViewController2: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

tableView2.addSubview(refreshControl) // Added Line

}





share|improve this answer
























  • It's not working, but thank you for your advise!

    – himiyo3in
    Nov 22 '18 at 8:39











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424665%2fswift4uirefreshcontrol-indicator-appear-at-different-position%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














This happens because of combination of things.




  1. You're using large headers for navigation controller. That makes TableViewController (actually any scrollable view) to put its refreshControl on navigation bar . This behaviour was introduced in iOS 11 https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles


  2. You're using two scrollable views and one of them binds to navigation bar and another is not. During debug I've found out that the first scrollable view in hierarchy attached its refreshControl to navigation bar.



So, that's means we can fix it by putting some fake or dummy scrollable view somewhere on the bottom of hierarchy in order to it binds its refreshControl to navigation bar first. Starting from iOS 11 any scrollable view may have refreshControl and its "binded" even if you don't declare it explicitly.



In your case you might just add UIScrollView before container in this way:




- View
-- Safe Area
-- UIScrollView (dummy)
-- ContainerView
---- TableView 1
---- TableView 2
...






share|improve this answer


























  • @iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

    – himiyo3in
    Nov 22 '18 at 8:37











  • @ilya ..Amazing solution along with description !!!

    – SachinVsSachin
    Nov 22 '18 at 9:30
















2














This happens because of combination of things.




  1. You're using large headers for navigation controller. That makes TableViewController (actually any scrollable view) to put its refreshControl on navigation bar . This behaviour was introduced in iOS 11 https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles


  2. You're using two scrollable views and one of them binds to navigation bar and another is not. During debug I've found out that the first scrollable view in hierarchy attached its refreshControl to navigation bar.



So, that's means we can fix it by putting some fake or dummy scrollable view somewhere on the bottom of hierarchy in order to it binds its refreshControl to navigation bar first. Starting from iOS 11 any scrollable view may have refreshControl and its "binded" even if you don't declare it explicitly.



In your case you might just add UIScrollView before container in this way:




- View
-- Safe Area
-- UIScrollView (dummy)
-- ContainerView
---- TableView 1
---- TableView 2
...






share|improve this answer


























  • @iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

    – himiyo3in
    Nov 22 '18 at 8:37











  • @ilya ..Amazing solution along with description !!!

    – SachinVsSachin
    Nov 22 '18 at 9:30














2












2








2







This happens because of combination of things.




  1. You're using large headers for navigation controller. That makes TableViewController (actually any scrollable view) to put its refreshControl on navigation bar . This behaviour was introduced in iOS 11 https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles


  2. You're using two scrollable views and one of them binds to navigation bar and another is not. During debug I've found out that the first scrollable view in hierarchy attached its refreshControl to navigation bar.



So, that's means we can fix it by putting some fake or dummy scrollable view somewhere on the bottom of hierarchy in order to it binds its refreshControl to navigation bar first. Starting from iOS 11 any scrollable view may have refreshControl and its "binded" even if you don't declare it explicitly.



In your case you might just add UIScrollView before container in this way:




- View
-- Safe Area
-- UIScrollView (dummy)
-- ContainerView
---- TableView 1
---- TableView 2
...






share|improve this answer















This happens because of combination of things.




  1. You're using large headers for navigation controller. That makes TableViewController (actually any scrollable view) to put its refreshControl on navigation bar . This behaviour was introduced in iOS 11 https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles


  2. You're using two scrollable views and one of them binds to navigation bar and another is not. During debug I've found out that the first scrollable view in hierarchy attached its refreshControl to navigation bar.



So, that's means we can fix it by putting some fake or dummy scrollable view somewhere on the bottom of hierarchy in order to it binds its refreshControl to navigation bar first. Starting from iOS 11 any scrollable view may have refreshControl and its "binded" even if you don't declare it explicitly.



In your case you might just add UIScrollView before container in this way:




- View
-- Safe Area
-- UIScrollView (dummy)
-- ContainerView
---- TableView 1
---- TableView 2
...







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 7:45

























answered Nov 22 '18 at 7:40









ilyailya

1,0151114




1,0151114













  • @iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

    – himiyo3in
    Nov 22 '18 at 8:37











  • @ilya ..Amazing solution along with description !!!

    – SachinVsSachin
    Nov 22 '18 at 9:30



















  • @iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

    – himiyo3in
    Nov 22 '18 at 8:37











  • @ilya ..Amazing solution along with description !!!

    – SachinVsSachin
    Nov 22 '18 at 9:30

















@iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

– himiyo3in
Nov 22 '18 at 8:37





@iiya OMG! The issue is solved by this method!! Thanks a lot!!!!

– himiyo3in
Nov 22 '18 at 8:37













@ilya ..Amazing solution along with description !!!

– SachinVsSachin
Nov 22 '18 at 9:30





@ilya ..Amazing solution along with description !!!

– SachinVsSachin
Nov 22 '18 at 9:30













0














Try this--



class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
//Updated code.. this will fix it
self.tableView.addSubview(refreshControl)

}


Let us know .. is working ?






share|improve this answer
























  • tableviewcontroller already have refreshControl property.

    – Lal Krishna
    Nov 22 '18 at 6:36











  • but this time new allocations has happened.. so there I have doubt over to added view in tableView..

    – SachinVsSachin
    Nov 22 '18 at 6:38











  • @SachinVsSachin Thank you for your advise, but it's not working...

    – himiyo3in
    Nov 22 '18 at 8:31
















0














Try this--



class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
//Updated code.. this will fix it
self.tableView.addSubview(refreshControl)

}


Let us know .. is working ?






share|improve this answer
























  • tableviewcontroller already have refreshControl property.

    – Lal Krishna
    Nov 22 '18 at 6:36











  • but this time new allocations has happened.. so there I have doubt over to added view in tableView..

    – SachinVsSachin
    Nov 22 '18 at 6:38











  • @SachinVsSachin Thank you for your advise, but it's not working...

    – himiyo3in
    Nov 22 '18 at 8:31














0












0








0







Try this--



class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
//Updated code.. this will fix it
self.tableView.addSubview(refreshControl)

}


Let us know .. is working ?






share|improve this answer













Try this--



class TableViewController2: UITableViewController  {

override func viewDidLoad() {
super.viewDidLoad()

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
//Updated code.. this will fix it
self.tableView.addSubview(refreshControl)

}


Let us know .. is working ?







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 6:33









SachinVsSachinSachinVsSachin

5,02112735




5,02112735













  • tableviewcontroller already have refreshControl property.

    – Lal Krishna
    Nov 22 '18 at 6:36











  • but this time new allocations has happened.. so there I have doubt over to added view in tableView..

    – SachinVsSachin
    Nov 22 '18 at 6:38











  • @SachinVsSachin Thank you for your advise, but it's not working...

    – himiyo3in
    Nov 22 '18 at 8:31



















  • tableviewcontroller already have refreshControl property.

    – Lal Krishna
    Nov 22 '18 at 6:36











  • but this time new allocations has happened.. so there I have doubt over to added view in tableView..

    – SachinVsSachin
    Nov 22 '18 at 6:38











  • @SachinVsSachin Thank you for your advise, but it's not working...

    – himiyo3in
    Nov 22 '18 at 8:31

















tableviewcontroller already have refreshControl property.

– Lal Krishna
Nov 22 '18 at 6:36





tableviewcontroller already have refreshControl property.

– Lal Krishna
Nov 22 '18 at 6:36













but this time new allocations has happened.. so there I have doubt over to added view in tableView..

– SachinVsSachin
Nov 22 '18 at 6:38





but this time new allocations has happened.. so there I have doubt over to added view in tableView..

– SachinVsSachin
Nov 22 '18 at 6:38













@SachinVsSachin Thank you for your advise, but it's not working...

– himiyo3in
Nov 22 '18 at 8:31





@SachinVsSachin Thank you for your advise, but it's not working...

– himiyo3in
Nov 22 '18 at 8:31











0














TableviewController 1



class TableViewController1: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
tableView1.addSubview(refreshControl) // Added Line

}


TableviewController 2



class TableViewController2: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

tableView2.addSubview(refreshControl) // Added Line

}





share|improve this answer
























  • It's not working, but thank you for your advise!

    – himiyo3in
    Nov 22 '18 at 8:39
















0














TableviewController 1



class TableViewController1: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
tableView1.addSubview(refreshControl) // Added Line

}


TableviewController 2



class TableViewController2: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

tableView2.addSubview(refreshControl) // Added Line

}





share|improve this answer
























  • It's not working, but thank you for your advise!

    – himiyo3in
    Nov 22 '18 at 8:39














0












0








0







TableviewController 1



class TableViewController1: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
tableView1.addSubview(refreshControl) // Added Line

}


TableviewController 2



class TableViewController2: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

tableView2.addSubview(refreshControl) // Added Line

}





share|improve this answer













TableviewController 1



class TableViewController1: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
tableView1.addSubview(refreshControl) // Added Line

}


TableviewController 2



class TableViewController2: UITableViewController  {

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()


refreshControl?.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

tableView2.addSubview(refreshControl) // Added Line

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 7:22









Trupesh VaghasiyaTrupesh Vaghasiya

818




818













  • It's not working, but thank you for your advise!

    – himiyo3in
    Nov 22 '18 at 8:39



















  • It's not working, but thank you for your advise!

    – himiyo3in
    Nov 22 '18 at 8:39

















It's not working, but thank you for your advise!

– himiyo3in
Nov 22 '18 at 8:39





It's not working, but thank you for your advise!

– himiyo3in
Nov 22 '18 at 8:39


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424665%2fswift4uirefreshcontrol-indicator-appear-at-different-position%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()