我使用标准标签栏应用程序作为测试应用程序的基础。
我也在尝试使用在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
中#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
当您单击该按钮时,您会收到一条消息“deallocing ELCImagePickerController”,因此它正在调用ELCImagePickerController类,但它不会显示图像选择器。任何想法都将不胜感激。
由于
答案 0 :(得分:1)
在launchController()
方法中,您将appDelegate
转换为viewController
,这在逻辑上是错误的。您需要使用实际的viewController
到presentModalViewController
。尝试:
[self presentModalViewController:elcPicker animated:YES];