2012-02-14 7 views
0

私は、標準のタブバーアプリケーションをテストアプリケーションの基礎として使用しています。ボタンからイメージピッカーを起動できません

githubにあるELCAlbumPickerControllerクラスも使用しようとしています。

写真ピッカーとUIScrollViewのを起動するボタンが以下のSecondview.xib

に位置していることSecondViewController.h

#import <UIKit/UIKit.h> 
#import "ELCImagePickerController.h" 


@interface SecondViewController : UIViewController  <ELCImagePickerControllerDelegate,UINavigationControllerDelegate, UIScrollViewDelegate>{ 
    UIWindow *window; 
    SecondViewController *viewController; 
    IBOutlet UIScrollView *scrollview; 

} 

@property (nonatomic,retain) IBOutlet UIWindow *window; 
@property (nonatomic,retain) IBOutlet SecondViewController *viewController; 
@property (nonatomic,retain) IBOutlet UIScrollView *scrollview; 

-(IBAction)launchController; 

@end 

のコードであり、次はSecondViewController.mでありますそれはELCImagePickerControlを呼び出しているので、あなたが「ELCImagePickerControllerをdeallocing」というメッセージを取得]ボタンをクリックし

#import "myappAppDelegate.h" 
#import "SecondViewController.h" 
#import "ELCImagePickerController.h" 
#import "ELCAlbumPickerController.h" 

@implementation SecondViewController 

@synthesize window; 
@synthesize viewController; 
@synthesize scrollview; 


/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.*/ 
- (void)viewDidLoad 
{ 

    //[self launchController:self]; 
    [super viewDidLoad]; 
} 


- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

-(IBAction)launchController { 

    ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];  
    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController]; 
    [albumController setParent:elcPicker]; 
    [elcPicker setDelegate:self]; 

    //myappAppDelegate *app = (myappAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    SecondViewController *app = (SecondViewController *)[[UIApplication sharedApplication] delegate]; 
    [app.viewController presentModalViewController:elcPicker animated:YES]; 
    [elcPicker release]; 
    [albumController release]; 
} 

#pragma mark ELCImagePickerControllerDelegate Methods 

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info { 

    [self dismissModalViewControllerAnimated:YES]; 

    for (UIView *v in [scrollview subviews]) { 
    [v removeFromSuperview]; 
    } 

CGRect workingFrame = scrollview.frame; 
workingFrame.origin.x = 0; 

for(NSDictionary *dict in info) { 

    UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]]; 
    [imageview setContentMode:UIViewContentModeScaleAspectFit]; 
    imageview.frame = workingFrame; 

    [scrollview addSubview:imageview]; 
    [imageview release]; 

    workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width; 
} 

[scrollview setPagingEnabled:YES]; 
[scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)]; 
} 

- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker { 

[self dismissModalViewControllerAnimated:YES]; 
} 


- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload 
    { 
    [super viewDidUnload]; 

    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    } 


- (void)dealloc 
{ 
    [super dealloc]; 
} 

@end 

それは画像ピッカーを表示していません。任意のアイデアをいただければ幸いです。

おかげlaunchController()方法で

答えて

1

は、あなたは論理的に間違っている、viewControllerappDelegateを鋳造しました。実際のviewControllerpresentModalViewControllerを使用する必要があります。試してください:

[self presentModalViewController:elcPicker animated:YES]; 
+0

'presentModalViewController'は廃止予定です – Raptor

関連する問題