when I call removeFromSuperview from my view.m file( [self removeFromSuperview]; ), it seems working fine. but when I call that method from the view controller.m file([self.view removeFromSuperview]) it only returns error. I have no idea what is wrong about it.
when I call removeFromSuperview from my view.m file( [self removeFromSuperview]; ), it seems working
Share
I am guessing your view is one of the subviews in your controller’s view. Calling [self.view removeFromSuperview] only tries to remove the controller’s view from the parent view. This is probably not what you want to do. You need to find the child of self.view that is of your view’s type ( or using a tag) and then remove it.
Without the exact code this is what you need to do.
When you are ready to remove the view loop through the subviews of controllers view and if the subview’s tag is 42 then do a removeFromSuperview on that view. So something like this
for (UIView *view in [self.view subviews] ) {
if (view.tag == 42 ) {
[view removeFromSuperview];
}
}