i have a scrollView, and i added a refreshcontroll to it.
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Frissítéshez húzzad! :)")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.scrollView.addSubview(refreshControl)
in the refresh method i have to remove all subviews from the scrollview, then repopulate the scrollview..
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Frissítéshez húzzad! :)")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.scrollView.addSubview(refreshControl)
after i try to pull, my scrollview get new data but it's don't have anymore refreshcontroll. i think it is because when i removing subviews from my scrollview i also remove the refreshcontroll from it. (if i add the refreshcontroll again in my refresh method my scrollview will have refreshconroll again) But there is another problem. After refreshing my scrollview moving down.. i attached to pictures:
This is how i remove the subiews:
func refresh(sender:AnyObject)
{
//remove all subviews from scrollview..
let subViews = self.scrollView.subviews
for subview in subViews{
println("for removing...")
subview.removeFromSuperview()
}
println("refresh called..")
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
//remove all elements from the array
tstFrames.removeAll(keepCapacity: false)
//refresh data from webservice and adding it to tstFrames Array
wsServiceFeedTst()
//adding items to the scrollview from tstFramesArray
addPosts()
self.refreshControl.endRefreshing()
}
This is how scrollview look like before refreshing:
An this is how it looks like after refreshing:
could anybody help me about why is this moving down?
Thank you!
Thank you, this is the solution:
let subViews = self.scrollView.subviews
for subview in subViews{
println("for removing...")
if (subview is PostLineItem) {
subview.removeFromSuperview()
}
else {
println("not removing..")
}
}