gpt4 book ai didi

ios - 从按钮启动图像选择器不起作用

转载 作者:行者123 更新时间:2023-11-29 04:48:20 24 4
gpt4 key购买 nike

我使用标准标签栏应用程序作为测试应用程序的基础。

我还尝试使用在 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

当您单击该按钮时,您会收到一条消息“正在解除分配 ELCImagePickerController”,因此它正在调用 ELCImagePickerController 类,但它只是不显示图像选择器。任何想法将不胜感激。

谢谢

最佳答案

launchController() 方法中,您将 appDelegate 转换为 viewController,这在逻辑上是错误的。您需要使用实际的viewControllerpresentModalViewController。尝试:

[self presentModalViewController:elcPicker animated:YES];

关于ios - 从按钮启动图像选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com