我有我自己的 UIView :
#import <UIKit/UIKit.h>
@interface MultipleSlotsClientView : UIView
-(IBAction)didPressCloseBtn:(id)sender;
@end
这是实现:
@implementation MultipleSlotsClientView
- (id)initWithFrame:(CGRect)frame {
self = [[[[NSBundle mainBundle] loadNibNamed:@"MultipleSlotsClientView" owner:self options:nil] objectAtIndex:0] retain];
if (self) {
self.frame = frame;
}
return self;
}
#pragma mark
#pragma mark IBAction
-(IBAction)didPressCloseBtn:(id)sender {
[self removeFromSuperview];
}
@end
而且我有一个连接到该didPressCloseBtn
方法的 btn,当我按下按钮时,该方法调用但视图不会从超级视图中删除。
这就是我分配 UIView 并添加它的方式:
MultipleSlotsClientView *multiView = [[[MultipleSlotsClientView alloc] initWithFrame:self.view.frame] autorelease];
[self.view addSubview:multiView];
知道为什么视图不会消失吗?