我有一个 UIViewController 的子类 -> MyPopUpViewController
@protocol MyPopUpViewController Delegate;
@interface MyPopUpViewController : UIViewController
{
}
@property (nonatomic, strong) id <MyPopUpViewControllerDelegate> delegate;
-(IBAction) buttonPressed:(id)sender;
@end
@protocol MyPopUpViewControllerDelegate
-(void) popupButtonPressed: (MyPopUpViewController*)controller;
@end
我不能将这个 MyPopUpViewController 作为实例变量,因为它来自外部,并且可能有很多和多个这样的弹出窗口可以出现。到目前为止,我尝试了这个,由于没有被保留,它在委托调用中崩溃:
我的主视图控制器:
-(void)externalNotificationReceived: (NSString*) sentMessage
{
MyPopUpViewController *popupView = [[MyPopUpViewController alloc] init];
popupView.delegate = self;
[self.view addSubview:popupView.view];
[popupView setInfo :sentMessage :@"View" :@"Okay"];
popupView.view.frame = CGRectMake(0, -568, 320, 568);
popupView.view.center = self.view.center;
}
-(void)popupButtonPressed:(MyPopUpViewController *)controller :(int)sentButtonNumber
{
NSLog(@"Popup Delegate Called");
[controller.view removeFromSuperview];
controller.delegate = nil;
controller = nil;
}
一旦弹出窗口出现,当点击确定按钮时,它就会崩溃并且永远不会到达那个 NSLog。我该如何改变
MyPopUpViewController *popupView = [[MyPopUpViewController alloc] init];
..所以它会保留而不使其成为实例变量?
提前致谢。