I am trying to remove all the subviews from a UIView. I tried the following to no effect:
for (int i = 0; i < this.Subviews.Length; i++)
{
this.Subviews[i].RemoveFromSuperview ();
}
Just tested this and it worked for me. (Although your code also looks good to me...)
foreach (UIView view in tableView.Subviews) {
view.RemoveFromSuperview();
}
If it doesn't work for you, there might be something that prevents the subviews from being removed.
The problem with your sample is how you built the loop.
When you remove the view at 0, the Subviews array is one element shorter, and element 1 becomes element 0 on the next iteration. Your i variable on the other hand keeps growing, so you end up skipping view 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With