I try to remove the buttons in one of my view controllers, somehow this results in a crash.
The code below actually executes and also the number of buttons is correct. For safety reasons I added the check if it is a UIButton class, although not needed.
At the end of my function viewWillDisappear this crashes.
So what do I forget ?
for(UIView *subview in [self.view subviews]) {
NSLog(@"subviews Count=%d",[[self.view subviews]count]);
if ([subview isKindOfClass:[UIButton class]]) {
[subview removeFromSuperview];
}
Your code looks ok. One common error to watch out for is creating a UIButton like this
and then releasing this when it has not been retained (and therefore doesn’t need to be released).
Also, why are removing buttons from a view when that view is about to disappear?
Please post more info about your crash – what does the log say?