1

我正在撕裂我的头发,我已经将我的旧项目迁移到弧线,并且出现此错误弹出:*由于未捕获的异常'NSGenericException',原因:' - [UIPopoverController dealloc]在popover仍然可见时到达。'ARC和Popovers和代表

我已经通读了一些线程,我很困惑,有人说当使用委托使用弱引用,但另一方面,当使用弹出使用强大的属性引用时,有人可以给我一个如何最好地使用ARC和带有弹出窗口的代表,其中有一个用于更改背景颜色的按钮?

从我读过我不断听到用一个实例变量在我的视图控制器,这里是我的主视图控制器:

@property (nonatomic, strong) UIPopoverController *currentPopover; 

和在主视图控制器文件的方法实现:

- (IBAction)ShowPopTextColor:(id)sender { 

if (currentPopover == nil) { 

TimerTextColor *timerTextColor = [[TimerTextColor alloc]init]; 
timerTextColor.delegate =self; 
UIPopoverController *pop = [[UIPopoverController     alloc]initWithContentViewController:timerTextColor]; 
[pop setDelegate:self]; 
    [pop setPopoverContentSize:CGSizeMake(320, 240)]; 
[pop presentPopoverFromBarButtonItem:sender  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

//[pop release]; 

} else { 

    [currentPopover dismissPopoverAnimated:YES]; 
    currentPopover = nil; 
} 

} 

这里是我的弹出内容标题:

@protocol colorChooserDelegate 

-(void) colorSelected:(UIColor*)thecolor; 

@end 

@interface TimerTextColor : UIViewController{ 

id<colorChooserDelegate> delegate; 

IBOutlet UIButton *colorView; 

} 

- (IBAction)buttonTapped:(id) sender; 
@property (nonatomic,strong) id<colorChooserDelegate>delegate; 
@property (nonatomic,strong) UIButton *colorView; 

@end 

上午什么我做错了?

回答

1

指定currentPopover。 呼叫

currentPopover = pop 

酥料饼的制作后

+0

谢谢!我的注意力集中在弧线上,我是盲目的!这段代码在弧之前工作,所以我甚至没有考虑将我的本地分配给我的实例变量!再次感谢您指出。 – 2012-03-07 19:43:46

1

你不应该创建一个局部变量来存储酥料饼的控制器。

更改此

UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:timerTextColor]; 

self.currentPopover = [[UIPopoverController alloc] initWithContentViewController:timerTextColor];