I followed this tutorial, and included a video player in my app.
But the problem is that i want to hide the controls, and be able to dismiss the video on screen touch.
I tried putting a big transparent button in front of the video that triggers the dismiss function, but with no luck. the video will always be over the button and the function will never be called.
Is there another way of doing it?
ty
**Hi I think AVPlayer is become more suitable to you,You can use it as below and then add subview if you want to play and if you want to stop remove it from super view
** #import"AVFoundation/AVFoundation.h"
**For creating Player List:
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"hello" ofType:#"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]];
player= [AVPlayer playerWithPlayerItem:first];
[self.playerView setPlayer:player];
[player play];
** You have to make uiview for playerview in it :
(id)initWithFrame:(CGRect)frame {self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
-(AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
-(void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
PlayerViewControll .H
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface PlayerView : UIView UILabel *pageNumberLabel;
int pageNumber;
}
#property (nonatomic, retain) AVPlayer *player;
- (id)initWithPageNumber:(int)page;
PlayerView .M
#import "PlayerView.h"
#implementation PlayerView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {}
return self;
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
MainViewControll .H
#import <AVFoundation/AVFoundation.h>
#import "PlayerView.h"
#interface MainViewController : UIViewController {
IBOutlet PlayerView *playerView;
NSString *url;
AVPlayer *player;
NSMutableArray *arrIteam;
}
#property(nonatomic,retain) NSMutableArray *arrIteam;
#property (nonatomic, retain) AVPlayer *player;
#property(nonatomic ,retain)IBOutlet PlayerView *playerView;
PlayerView.M
#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation MainViewController
#synthesize player,playerView,arrIteam;
- (void)viewDidLoad {
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"hello" ofType:#"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]];
arrIteam = [[NSMutableArray alloc] initWithObjects:first,second, third,fourth,nil];
player=[AVPlayer playerWithPlayerItem:[arrIteam objectAtIndex:i]];
[self.playerView setPlayer:player];
[player play];
[super viewDidLoad];
}
You should use UIGestureRecognizer class. See manual for details. Or read this tutorial.
Use this code.
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(stopPlayer)];
[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
[gestureRecognizer release];
in view didload;
And in
- (void) stopPlayer
stop the player and release this player from view.
Hope it helps you.
i just found the solution to my problem in another question asked here. after some minor modifications, the code worked as expected. thank you all.
Related
In this code a user gets and displays a photo (provided for now) in ImageViewController, adds a caption, and the the photo and caption are passed to the MTViewcontroller where it is made into a pdf. I have solved the PDF portion, but struggling with the segue. Appreciate any guidance. I can't find an example quite like this.
ImageViewController.h
#import <UIKit/UIKit.h>
#interface ImageViewController : UIViewController
{
NSURL *url;
UIImage *imageRoll;
}
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#property (strong, nonatomic) IBOutlet UITextField *enterCaption;
- (IBAction)Button:(id)sender;
#end
ImageViewController.m Not sure I'm treating imageRoll correctly and I can't find the right segue format for this. Once the user, submits the caption it would segue to the PDF controller. BUT, would the keyboard release given the segue?
- (void)viewDidLoad
{
[super viewDidLoad];
// Since iPhone simulator doesn't have photos, load and display a placeholder image
NSString *fPath = [[NSBundle mainBundle] pathForResource:#"IMG_3997" ofType:#"jpg"];
url = [NSURL fileURLWithPath:fPath];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
UIImage *imageRoll = [UIImage imageWithContentsOfFile:fPath];
}
// User provides a caption for the image
- (IBAction)Button:(id)sender {
NSString *caption = enterCaption.text;
[self performSegueWithIdentifier:#"showPDF" sender:sender];
MTViewController *vc1 = [segue destinationViewController];
vc1.photoCaption = caption;
MTViewController *vc2 = [segue destinationViewController];
vc2.photoImage = imageRoll;
}
//Dismiss Keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
MTViewController.h
#import <UIKit/UIKit.h>
#import "ReaderViewController.h"
#interface MTViewController : UIViewController <ReaderViewControllerDelegate>
#property(nonatomic, assign) NSString *photoCaption;
#property(nonatomic, assign) UIImage *photoImage;
- (IBAction)didClickMakePDF:(id)sender;
#end
MTViewController.m Have I passed and used photoCaption and photoImage correctly?
- (IBAction)didClickMakePDF {
[self setupPDFDocumentNamed:#"NewPDF" Width:850 Height:1100];
[self beginPDFPage];
CGRect textRect = [self addText:photoCaption
withFrame:CGRectMake(kPadding, kPadding, 400, 200) fontSize:48.0f];
CGRect blueLineRect = [self addLineWithFrame:CGRectMake(kPadding, textRect.origin.y + textRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor blueColor]];
UIImage *anImage = [UIImage imageNamed:#"photoImage"];
CGRect imageRect = [self addImage:anImage
atPoint:CGPointMake((_pageSize.width/2)-(anImage.size.width/2), blueLineRect.origin.y + blueLineRect.size.height + kPadding)];
[self addLineWithFrame:CGRectMake(kPadding, imageRect.origin.y + imageRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor redColor]];
[self finishPDF];
}
updated:
You should use self.xxx = xxx to save it in one method and get it back in another method by using self.xxx. For example you should use
self.imageRoll = [UIImage imageWithContentsOfFile:fPath];
instead of declaring a new imageRoll in your code. And it's the same with your caption.
The way you use segue is incorrect.
The way you call [self performSegueWithIdentifier:#"showPDF" sender:sender]; is correct. But then you can do some customization in
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"showPDF"]) {
MTViewController *vc1 = [segue destinationViewController];
vc1.photoCaption = self.caption;
vc1.photoImage = self.imageRoll;
}
}
Here is my code
AppDelegate.m
I use this code to start AVAudioPlayer. It works fine.
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:#"/Helloween.mp3"];
NSLog(#"Path to play: %#", resourcePath);
NSError* err;
//Initialize our player pointing to the path to our resource
backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(#"Failed with reason: %#", [err localizedDescription]);
}
else{
//set our delegate and begin playback
backgroundMusic.delegate = self;
[backgroundMusic play];
backgroundMusic.numberOfLoops = -1;
backgroundMusic.currentTime = 0;
backgroundMusic.volume = 1.0;
}
// Override point for customization after application launch.
return YES;
}
In AppDelegate.h I add framework and AVAudioPlayer
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
AVAudioPlayer *backgroundMusic;
}
#property(nonatomic,retain) AVAudioPlayer *backgroundMusic;
#property (strong, nonatomic) UIWindow *window;
#end
In ViewController.m i also add framework AVFoundation and import AppDelegate.h
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <CoreData/CoreData.h>
#define fName #"data.plist"
#define kNames #"data.plist"
#import <AVFoundation/AVFoundation.h>
#import "AppDelegate.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize backgroundMusic;
-(IBAction)stopMusic:(id)sender {
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.backgroundMusic stop];
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//set the position of the button
button.frame = CGRectMake(100, 100, 20, 20);
button.backgroundColor = [UIColor whiteColor];
[button addTarget:self action:#selector(stopMusic:) forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[self.view addSubview:button];
ViewController.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreData/CoreData.h>
#define kNames #"data.plist"
#import <AVFoundation/AVFoundation.h>
#interface ViewController : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *backgroundMusic;
}
I need stop the AudioPlayer with button.
Here is my code
AppDelegate.m
I use this code to start AVAudioPlayer.
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:#"/Helloween.mp3"];
NSLog(#"Path to play: %#", resourcePath);
NSError* err;
//Initialize our player pointing to the path to our resource
backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(#"Failed with reason: %#", [err localizedDescription]);
}
else{
//set our delegate and begin playback
backgroundMusic.delegate = self;
[backgroundMusic play];
backgroundMusic.numberOfLoops = -1;
backgroundMusic.currentTime = 0;
backgroundMusic.volume = 1.0;
}
// Override point for customization after application launch.
return YES;
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
AVAudioPlayer *backgroundMusic;
}
-(IBAction)stopMus:(id)sender;
#property(nonatomic,retain) AVAudioPlayer *backgroundMusic;
#property (strong, nonatomic) UIWindow *window;
#end
ViewController.m
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <CoreData/CoreData.h>
#define fName #"data.plist"
#define kNames #"data.plist"
#import <AVFoundation/AVFoundation.h>
#import "AppDelegate.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize backgroundMusic;
-(IBAction)stopMusic:(id)sender {
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.backgroundMusic stop];
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//set the position of the button
button.frame = CGRectMake(100, 100, 20, 20);
button.backgroundColor = [UIColor whiteColor];
[button addTarget:self action:#selector(stopMusic:) forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[self.view addSubview:button];
ViewController.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreData/CoreData.h>
#define kNames #"data.plist"
#import <AVFoundation/AVFoundation.h>
#interface ViewController : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *backgroundMusic;
}
I need stop the AudioPlayer with button.
First, add UIButton to the UIView like this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//set the position of the button
button.frame = CGRectMake(0, 0, 0, 0);
[button addTarget:self action:#selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[self.view addSubview:button];
Then,
-(IBAction)yourMethod:(id)sender {
[backgroundMusic stop];
}
After your done with the button, you can remove it via [button removeFromSuperView];
I think, something like that should work :) Please ask if your having problem with my answer.
So I created a program where a sound occurs when the device is shaken. Theres a button, that when tapped stops the sound from being played at any time (This is the "reset" method). There's another button, that when pushed displays another view (This is the "infoView" method). The problem occurs when I go the "infoView" then go back to the first view. The sound still play when the device is shaken but the "reset" button becomes unresponsive. Here's what I have so far, any help would be appreciated.
PS. I'm wondering if it has anything to do with FirstResponders? I'm still trying to wrap my head around FirstResponders.
The .h
#import <UIKit/UIKit.h>
#import "AVfoundation/AVfoundation.h"
#interface OldTvViewController : UIViewController{
AVAudioPlayer *audioPlayer;
}
-(IBAction)reset;
-(IBAction)infoView:(id)sender;
#end
the .m
#import "OldTvViewController.h"
#import "AudioToolBox/AudioToolBox.h"
#import "infoViewController.h"
#implementation OldTvViewController
-(IBAction)infoView:(id)sender{
infoViewController *second = [[infoViewController alloc] initWithNibName:Nil bundle:Nil];
[self presentModalViewController:second animated:YES];
[second release];
}
-(BOOL) canBecomeFirstResponder{
return YES;
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (event.subtype == UIEventSubtypeMotionShake) {
//Play throw sound
if(audioPlayer.playing){
[audioPlayer stop];
} else{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/bomb.mp3",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
}
}
}
-(IBAction)reset{
[audioPlayer stop];
}
-(void)viewDidAppear:(BOOL)animated{
[self becomeFirstResponder];
[super viewDidAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
#end
when You go to info view then where your all button available in that class you try this code.
-(void)viewWillDisapeers
{
[audioPlayer stop];
}
or add in this method
-(IBAction)infoView:(id)sender
{
infoViewController *second = [[infoViewController alloc] initWithNibName:Nil bundle:Nil];
[self presentModalViewController:second animated:YES];
[audioPlayer stop];
[second release];
}
I want to make a app where I need to have a toolbar. The toolbar will have various number of objects (images). These objects should be draggable and placed on view right above it.
This is a kind of drawing app where user can pick any shape and place on canvas. Can anyone tell me the best to achieve this ?
Thanks in advance.
Tough one.
What I would do is make each item on the toolbar a UIView and override touchesBegan, touchesEnded, and touchesMoved. Make your canvas another UIView. When a user clicks an item to drag, register that item somewhere, say a square. then when they drop on the canvas, draw that square at that location. To make it look pretty, would probably make a UIImageView with an alpha of like .4 to move with the user's touch, so they know what they are dragging, and where it will land.
Here is the code.
UIViewController.h
#class ToolBox;
#interface ViewController : UIViewController {
IBOutlet UIView *canvas;
IBOutlet ToolBox *toolBox;
}
#property (nonatomic, retain) UIView *canvas;
#property (nonatomic, retain) ToolBox *toolBox;
#end
UIViewController.m
#import "ViewController.h"
#import "ToolBox.h"
#import "Tool.h"
#implementation ViewController
#synthesize canvas, toolBox;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[self toolBox] setCanvas:[self canvas]];
Tool *tool = [[[Tool alloc] initWithFrame:CGRectMake(0,0,64,64)] autorelease];
[tool setImageView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"1.png"]] autorelease]];
[tool setImage:[UIImage imageNamed:#"1.png"]];
[tool addSubview:[tool imageView]];
[tool setToolBox:[self toolBox]];
[[self toolBox] addObject:tool];
}
#end
ToolBox.h
#class Tool;
#interface ToolBox : UIView {
NSMutableArray *tools;
UIView *canvas;
UIImage *currentTool;
}
#property (nonatomic, retain) UIImage *currentTool;
#property (nonatomic, retain) NSMutableArray *tools;
#property (nonatomic, retain) UIView *canvas;
-(void)addObject:(Tool *)newTool;
-(void)updatePositions;
#end
ToolBox.m
#implementation ToolBox
#synthesize tools, canvas, currentTool;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
-(void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
-(NSMutableArray *)tools {
if(tools == nil) {
[self setTools:[NSMutableArray array]];
}
return tools;
}
-(void)addObject:(Tool *)newTool {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(draggingTool:) name:#"Dragging New Tool" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(draggedTool:) name:#"Dragged Tool To" object:nil];
[[self tools] addObject:newTool];
[self updatePositions];
}
-(void)updatePositions {
int x = 0;
int y = 0;
int width = 64;
int height = 64;
for(Tool *button in [self tools]) {
[button setFrame:CGRectMake(x, y, width, height)];
x += width;
[self addSubview:button];
}
}
-(void)draggingTool:(NSNotification *)notif {
NSDictionary *dict = [notif userInfo];
UIImage *image = [dict valueForKey:#"Image"];
[self setCurrentTool:image];
}
-(void)draggedTool:(NSNotification *)notif {
UITouch *touch = [[notif userInfo] valueForKey:#"Touch"];
CGPoint point = [touch locationInView:canvas];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:currentTool] autorelease];
[imageView setCenter:point];
[canvas addSubview:imageView];
}
#end
Tool.h
#class ToolBox;
#interface Tool : UIView {
UIImageView *imageView;
UIImage *image;
UIImageView *ghostImageView;
ToolBox *toolBox;
}
#property (nonatomic, retain) UIImageView *imageView;
#property (nonatomic, retain) UIImage *image;
#property (nonatomic, retain) UIImageView *ghostImageView;
#property (nonatomic, retain) ToolBox *toolBox;
#end
Tool.m
#import "Tool.h"
#import "ToolBox.h"
#implementation Tool
#synthesize imageView, image, ghostImageView, toolBox;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"tool touches began");
NSDictionary *dict = [NSDictionary dictionaryWithObject:[self image] forKey:#"Image"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"Dragging New Tool" object:nil userInfo:dict];
UITouch *touch = [touches anyObject];
CGPoint center = [touch locationInView:[[self toolBox] canvas]];
[self setGhostImageView:[[[UIImageView alloc] initWithImage:[self image]] autorelease]];
[[self ghostImageView] setCenter:center];
[[[self toolBox] canvas] addSubview:[self ghostImageView]];
[[self ghostImageView] setAlpha:.4];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"tool touches ended");
NSDictionary *dict = [NSDictionary dictionaryWithObject:[touches anyObject] forKey:#"Touch"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"Dragged Tool To" object:nil userInfo:dict];
[self setGhostImageView:nil];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"tool touch moved");
if([self ghostImageView] != nil) {
UITouch *touch = [touches anyObject];
CGPoint center = [touch locationInView:[[self toolBox] canvas]];
NSLog(#"Ghost : %2f, %2f", center.x, center.y);
[[self ghostImageView] setCenter:center];
}
}
#end
My Program came out like this -
Initial screen: The tool is ready to be dragged and dropped onto the canvas
Dropped the tool on the canvas
And here is the ghost for the transition
I'm not exactly sure how this would be implemented in objective c, but I have done almost exactly what you are describing in java. Basically, when you begin to drag the object in the toolbar, it will recognize the action and store a new instance of the item in what I call a transfer container, which is basically a global static variable. That way when the drag action competes (I.e. drops) you can just grab that object from the container and add it to wherever it was dropped.
Well, i have 2 view controllers the fist has three buttons each one represents an image on an array of images. When a user presses a button moves on the second view controller which has just an IBOutlet UIImageView to view the image. How can i do this programming trick using the UIImagePickerController? here are my files:
// PhotoListViewController.h
#import <UIKit/UIKit.h>
#import "PhotoDetailViewController.h"
#interface PhotoListViewController : UIViewController {
IBOutlet UIButton *button;
IBOutlet UIImageView *image1;
IBOutlet UIImageView *image2;
IBOutlet UIImageView *image3;
IBOutlet UILabel *label1;
IBOutlet UILabel *label2;
IBOutlet UILabel *label3;
IBOutlet UILabel *nameMikro1;
IBOutlet UILabel *nameMikro2;
IBOutlet UILabel *nameMikro3;
NSString *nameMikroProp;
IBOutlet PhotoDetailViewController *photoDetailViewController;
}
#property (nonatomic, retain) PhotoDetailViewController *photoDetailViewController;
-(IBAction)showImage:(id)sender;
#property (copy) NSString *nameMikroProp;
#end
// PhotoListViewController.m
#import "PhotoListViewController.h"
#import "PhotoDetailViewController.h"
#implementation PhotoListViewController
#synthesize nameMikroProp;
#synthesize photoDetailViewController;
-(IBAction)showImage:(id)sender{
photoDetailViewController = [[PhotoDetailViewController alloc]init];
//photoDetailViewController.delegate = self;
if([sender tag] == 4){
//[photoDetailViewController.imageViewprop setImage:[UIImage imageNamed:#"zaab.png"]];
//[self presentModalViewController:self.imgPicker animated:YES];
}
else if([sender tag] == 5){
}
else{
}
[self.navigationController pushViewController:photoDetailViewController animated:YES];
[photoDetailViewController release];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"main" ofType:#"jpg"]]];
[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"main2" ofType:#"jpg"]]];
[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"main3" ofType:#"jpg"]]];
NSMutableArray *nameArray = [[NSMutableArray alloc] init];
[nameArray addObject:#"zaab's photo one"];
[nameArray addObject:#"zaab's photo two"];
[nameArray addObject:#"zaab's photo three"];
nameMikro1.text = nameMikroProp;
nameMikro2.text = nameMikroProp;
nameMikro3.text = nameMikroProp;
if([#"zaab" isEqualToString:nameMikro1.text]) {
[image1 setImage:[imageArray objectAtIndex:0]];
[image2 setImage:[imageArray objectAtIndex:1]];
[image3 setImage:[imageArray objectAtIndex:2]];
[label1 setText:[nameArray objectAtIndex:0]];
[label2 setText:[nameArray objectAtIndex:1]];
[label3 setText:[nameArray objectAtIndex:2]];
}
else if([#"evza" isEqualToString:nameMikro1.text]) {
[image1 setImage:[UIImage imageNamed:#"evza.jpg"]];
}
[imageArray release];
[nameArray release];
[super viewDidLoad];
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[nameMikro1 release];
[nameMikro2 release];
[nameMikro3 release];
[label1 release];
[label2 release];
[label3 release];
[image1 release];
[image2 release];
[image3 release];
[super dealloc];
}
#end
// PhotoDetailViewController.h
#import <UIKit/UIKit.h>
#interface PhotoDetailViewController : UIViewController<UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
IBOutlet UIImageView *imageViewprop;
UIImagePickerController *imgPicker;
}
#property (nonatomic, retain) UIImageView *imageViewprop;
#property (nonatomic, retain) UIImagePickerController *imgPicker;
- (IBAction)grabImage;
#end
// PhotoDetailViewController.m
#import "PhotoDetailViewController.h"
#implementation PhotoDetailViewController
#synthesize imageViewprop;
#synthesize imgPicker;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
imageViewprop.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"main" ofType:#"jpg"]];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (IBAction)grabImage {
[self presentModalViewController:self.imgPicker animated:YES];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Why do you need an image picker controller to show an image? ImagePickerController is used to pick an image from the album or by using camera.
What you can do is to pass the image from the PhotoListViewController to PhotoDetailViewController.
In the PhotoDetailViewController, you can have a property of UIImage (synthesized), so that you can set it before loading it. Then in the PhotoDetailVC use a UIImageView to show the image.
If you are looking for more advance functionality with image, look at the three20 framework at
three20 at github.