removeFromSuperview删除所有子视图

Rom*_*use 2 iphone objective-c ios

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSLog(@"will rotation");

    for (UIButton *button in self.view.subviews) {
        [button removeFromSuperview];
    }

}
Run Code Online (Sandbox Code Playgroud)

我有这个代码的问题.我需要从我的视图中删除UIButtons.但是这段代码也删除了我的self.view的所有子视图.我怎么解决这个问题?

Par*_*iya 5

做这个:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"will rotation");

   for (id subview in self.view.subviews) {
    if([subview isKindOfClass:[UIButton class]]) //remove only buttons
    {
      [subview removeFromSuperview];
    }
   }

}
Run Code Online (Sandbox Code Playgroud)