为什么myView在init之后是dealloc?
MainViewController:
[MOBubbleView hudWithBody:@"123123" bubblePoint:CGPointMake(220, headerMenu.center.y) hidesAfter:2 show:YES];
MOBubbleView.h:
@interface MOBubbleView : UIViewController
@property (nonatomic, assign) float hudHideDelay;
@property (nonatomic, strong) UIColor *itemColor;
+ (MOBubbleView*)hudWithBody:(NSString*)body bubblePoint:(CGPoint)rect hidesAfter:(float)delay show:(BOOL)show;
@end
MOBubbleView.m:
+ (MOBubbleView*)hudWithBody:(NSString*)body bubblePoint:(CGPoint)point hidesAfter:(float)delay show:(BOOL)show {
MOBubbleView *bubble = [[MOBubbleView alloc] init];
///....
if (show) [bubble addToWindow];
return bubble;
}
- (void)addToWindow {
[[[[UIApplication sharedApplication] delegate] window] addSubview:self.view];
}
- (void)loadView {
CGRect bounds = [[UIScreen mainScreen] bounds];
self.view = [[UIView alloc] initWithFrame:bounds];
[self.view setBackgroundColor:[UIColor clearColor]];
/// .. my animation
}
- (void) dealloc {
NSLog(@"Close myView");
}
@end
答案 0 :(得分:1)
您需要保留从通话中返回的视图控制器,所以:
pMyViewController = [myView hudWithBody:@"123123" bubblePoint:CGPointMake(220, headerMenu.center.y) hidesAfter:2 show:YES];
其中pMyViewController
声明它不会超出范围 - 比如说现在是一个全局变量:
e.g。 myView* pMyViewController;
您已将视图控制器的视图部分添加到窗口中,以便保留,但实际的控制器部分没有保留它的引用,因此它将被取消分配。