0

我无法访问在文件UIImagePickerController中定义的对象AppDelegate。我已经UIImagePickerControllerAppDelegate.h文件中定义了对象也使用了它的委托。这是我的代码。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    picker = [[UIImagePickerController alloc] init];  
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.wantsFullScreenLayout = YES;
    picker.allowsEditing=NO;

    return YES;
} 

我在 viewcontroller 文件中使用操作表并希望执行此操作 -

视图控制器.m

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (actionSheet.tag) 
    {
        case 1:
            switch (buttonIndex)
        {
            case 0:
            {
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
                [appDelegate.window.rootViewController presentModalViewController:appDelegate.picker animated:YES];
                    }
           }
     }
}

但图像选择器控制器视图未显示。

4

2 回答 2

0

我相信objective c 现在会自动合成您的属性并期待ivar 的_picker。用于表示法来访问您的选择器,例如 self.picker 或 self.delegate.picker

于 2012-10-17T08:40:38.610 回答
0

在你的

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

不要写

 [appDelegate.window.rootViewController presentModalViewController:appDelegate.picker animated:YES];

而是尝试写

 [appDelegate.window presentModalViewController:appDelegate.picker animated:YES];

让我知道它是否有效。!!!快乐编码!!!!

于 2012-11-01T12:38:54.040 回答