How do I remove all of the subviews from a UIScrollview?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
In addition to Ricardo de Cillo's, in my case I had a table view that had imageviews in the subviews that I wanted to remove.
The removal of the ! in the if command, and change
scrollview
toself.tableview
removed all images, but left the table view untouched.I think you just have to be careful and not to delete the scroll indicator bars.
The code given by Adam Ko is short and elegant but it may delete the horizontal and vertical scroll indicators.
I usually do
Suposing you don't have UIImageView's added to the scroll manually.
Complementing the Swift concise version from a previous answer (Swift 3.0 ready):
If you want to remove uiimageviews in scrollview.subviews, and you also want to keep the vertical and horizontal indicators. You can set a special "tag" to identify views and exclude vertical and horizontal indicators whose tags are 0 by default.
Let
scrollView
be an instance ofUIScrollView
.In Objective-C, it's pretty easy. Just call
makeObjectsPerformSelector:
, like so:Objective-C:
In Swift, you don't get that runtime access, so you have to actually handle the iteration yourself.
Swift:
A concise version, from here:
A more descriptive way to do this (from here) assumes
scrollview.subviews
: