当想要在通用应用程序中支持 iOS 4 及更高版本(适用于 iPhone 3G)时,是否有更短的方法来呈现视图控制器?
目前我在下面有这个,但我不喜欢如何需要一个UIPopoverController属性,其中我需要特别是因为如果观看控制器被挑选图像,则需要解雇POLPOVER时。
@interface SASuccessViewController ()
@property (nonatomic, retain) UIPopoverController *myPopoverController;
@end
@implementation SASuccessViewController
-(void)showViewController:(UIBarButtonItem *)sender {
UIViewController *viewController = [[UIViewController alloc] init];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:viewController animated:NO completion:nil];//iOS 5 and above
} else {
[self presentModalViewController:viewController animated:NO]; //iOS 4, deprecated in iOS 6
}
} else {
if (!self.myPopoverController) {
self.myPopoverController = [[[UIPopoverController alloc] initWithContentViewController:viewController] autorelease];
} else {
[self.myPopoverController setContentViewController:viewController];
}
[self.myPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
[viewController release];
}
-(void)dealloc {
[_popoverController release];
[super dealloc];
}
@end
考虑到当 iOS 4 是最新的(而不是通用应用程序)时,该方法将是:
-(void)showViewController:(UIBarButtonItem *)sender {
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[viewController release];
}
我现在看起来很臃肿。有没有更好的方法在通用应用程序上显示视图控制器(更不用说支持 iOS 4)?