我是Objective-C的新手,到目前为止我正在使用UIViewController并且我有两个UIPopoverControllers在其中工作但是我希望在我打开另一个时解除PopoverAnimated这里我已经得到的代码对他们来说很远:
-(IBAction)tabBtn1:(id)sender {
CapPhoto *capPhoto = [[CapPhoto alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:capPhoto];
[pop setDelegate:self];
[pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop setPopoverContentSize:CGSizeMake(200, 200)];
[capPhoto release];
}
-(IBAction)tabBtn2:(id)sender {
NewPhoto *newPhoto = [[NewPhoto alloc] init];
UIPopoverController *pop2 = [[UIPopoverController alloc] initWithContentViewController:newPhoto];
[pop2 setDelegate:self];
[pop2 presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop2 setPopoverContentSize:CGSizeMake(200, 200)];
[newPhoto release];
}
所以我已经分配了两个独立的.xib文件(CapPhoto和NewPhoto)作为PopoverControllers,我需要一个在调用另一个时解散。有任何想法吗?干杯!
答案 0 :(得分:1)
以下是关于如何在打开另一个时关闭UIPopoverController的解释:
在主viewcontroller.h文件中声明一个UIPopover控制器
@interface viewcontroller: UIViewController {
UIPopoverController *popOne;
UIPopoverController *popTwo;
}
- (IBAction)popOver:(id)sender;
@Property (nonatomic, retain) UIPopoverController *popOne'
@Property (nonatomic, retain) UIPopoverController *popTwo'
然后在你的视图controller.m文件中:
- (IBAction)popOver:(id)sender {
if ([popOne isPopoverVisible]) {
[popTwo dissmissPopoverAnimated:YES];
//in here is where you add things to your popover
//also note you can find tutorials on popovers this is just code to allow you to dismiss one when opening another. It'll make sense if you've followed a popover tutorial.
}
else {
[popOne dismissPopverAnimated:YES];
}
}
动臂。你做完了!