//
// MyController.m
// D
//
// Created by apple on 12-4-17.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "MyController.h"
#define MNSLog(info) NSLog(info)
@implementation MyController
-(IBAction) myMethod:(id)sender{
UIImagePickerController *pc = [[UIImagePickerController alloc]init];
pc.delegate = self;
pc.allowsEditing = NO;
//pc.allowsImageEditing = NO;
pc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pc animated:YES];
[pc release];
}
//3.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
MNSLog(@"3.x");
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImageView *iview = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:iview];
[self dismissModalViewControllerAnimated:YES];
}
//2.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
MNSLog(@"2.x");
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
MNSLog(@"cancle");
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"click" style:UIBarButtonItemStylePlain
target:self action:@selector(myMethod:)];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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
// MyController.m
// D
//
// Created by apple on 12-4-17.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "MyController.h"
#define MNSLog(info) NSLog(info)
@implementation MyController
-(IBAction) myMethod:(id)sender{
UIImagePickerController *pc = [[UIImagePickerController alloc]init];
pc.delegate = self;
pc.allowsEditing = NO;
//pc.allowsImageEditing = NO;
pc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pc animated:YES];
[pc release];
}
//3.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
MNSLog(@"3.x");
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImageView *iview = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:iview];
[self dismissModalViewControllerAnimated:YES];
}
//2.x
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
MNSLog(@"2.x");
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
MNSLog(@"cancle");
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"click" style:UIBarButtonItemStylePlain
target:self action:@selector(myMethod:)];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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