我正在尝试使 iPhone 应用程序在 iPad 上运行,但 UIPopoverController 出现错误。
- (IBAction)photoTapped1 {
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
// If in editing state, then display an image picker; if not, create and push a photo view controller.
if (self.editing) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
[imagePicker release];
} else {
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}
}else{
if (self.editing){
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
self.popover.delegate =self;
[popover release];
}else{
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}}}
我得到的错误是:'NSInvalidArgumentException',原因:'-[UIPopoverController initWithContentViewController:] 不能用nil
.'调用。
任何可以帮助我处理此代码的人,我已经在互联网上查看了解决方案和示例,但似乎无法使其工作。
谢谢你。
___添加到原始问题_ ____
我在这里添加 recipePhotoViewController,我假设 iPhone 和 iPad 的 ImageView 操作是相同的。
我的.h文件
@class Recipe;
@interface RecipePhotoViewController : UIViewController {
@private
Recipe *recipe;
UIImageView *imageView;
}
@property(nonatomic, retain) Recipe *recipe;
@property(nonatomic, retain) UIImageView *imageView;
@end
这是我的 .m 文件
@implementation RecipePhotoViewController
@synthesize recipe;
@synthesize imageView;
- (void)loadView {
self.title = @"Photo";
imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = [UIColor blackColor];
self.view = imageView; }
- (void)viewWillAppear:(BOOL)animated {
imageView.image = [recipe.image valueForKey:@"image"];}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[imageView release];
[recipe release];
[super dealloc];
} @end