2014-02-17 105 views

回答

0

我使用類中的方法爲這個

@interface UIView (Additions) 
- (void)removeAllSubviews 
@end 

@implementation UIView (Additions) 
- (void)removeAllSubviews 
{ 
    for (UIView *subview in self.subviews) 
     [subview removeFromSuperview]; 
} 
@end 

所以,你可以調用

[self.superview removeAllSubviews]; 

從上海華刪除一切。

+0

你應該總是使用類方法的前綴 –

0
for(UIView *view in self.superview.subviews) 
{ 
    [view removeFromSuperview]; 
} 

請注意,雖然它可以刪除您不知道的Apple內置程序,從而改變視圖與用戶交互的方式。

0

一個襯墊

[viewYouWantToRemoveFrom.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
相關問題