Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-19-2011, 11:58 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 37
VinC_HK is on a distinguished road
Default Importing image to another class.

Please download the attached file for your reference.
In the view controller file.
there is two methods, one is for opening the iphone photo library
and the other one is didFinishPickingImage:editingInfo.

after choosing the image, it will the bring the user to the SomeEdit file with .xib file
in the someEdit file there is a UIImageView already.
but the question is I don't know how to link the two files together.
to show the image in the someEdit interface.
Attached Files
File Type: zip CameraChoose 2.zip (24.7 KB, 5 views)
VinC_HK is offline   Reply With Quote
Old 09-19-2011, 12:33 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by VinC_HK View Post
Please download the attached file for your reference.
In the view controller file.
there is two methods, one is for opening the iphone photo library
and the other one is didFinishPickingImage:editingInfo.

after choosing the image, it will the bring the user to the SomeEdit file with .xib file
in the someEdit file there is a UIImageView already.
but the question is I don't know how to link the two files together.
to show the image in the someEdit interface.

Make a UIImage a property of SomeEdit. Let's cal it imageToDisplay.

Then you can set the property from another view controller.

Code:
SomeEdit* theSomeEditViewController;
//Create a new view controller or point to an existing one

theSomeEditViewController.imageToDisplay = theImage;
[myNavigationController 
  pushViewController:  theSomeEditViewController 
  animated: TRUE];
Then, in the SomeEdit view cotroller, put code in your viewWillAppear method that installs the image in the property into the image view.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-19-2011, 06:12 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 37
VinC_HK is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Make a UIImage a property of SomeEdit. Let's cal it imageToDisplay.

Then you can set the property from another view controller.

Code:
SomeEdit* theSomeEditViewController;
//Create a new view controller or point to an existing one

theSomeEditViewController.imageToDisplay = theImage;
[myNavigationController 
  pushViewController:  theSomeEditViewController 
  animated: TRUE];
Then, in the SomeEdit view cotroller, put code in your viewWillAppear method that installs the image in the property into the image view.
Code:
//In the CameraChooseViewController.m

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo {
    [picker dismissModalViewControllerAnimated:YES];
	
	SomeEdit* theSomeEditViewController;
	//Create a new view controller or point to an existing one
	
	theSomeEditViewController.imageToShow = image;
	 
	[CameraChooseViewController pushViewController:  theSomeEditViewController animated: TRUE];
	
}
// the SomeEdit.m file
- (void)viewDidLoad {	
	
	UIImage *img;
	if (img != nil) { // Image was loaded successfully.
		[img setImage:imageToShow];
		
		[img release]; // Release the image now that we have a UIImageView that contains it.
	}
	[super viewDidLoad];
}
Here's the update version of it.
but still won't work
Can anyone point out where I go wrong?
Attached Files
File Type: zip CameraChoose.zip (25.7 KB, 2 views)

Last edited by VinC_HK; 09-19-2011 at 06:15 PM.
VinC_HK is offline   Reply With Quote
Old 09-19-2011, 06:17 PM   #4 (permalink)
Registered Member
 
Objective Zero's Avatar
 
Join Date: Oct 2010
Posts: 1,210
Objective Zero is on a distinguished road
Default

Why are you releasing 'img'? UIImage's are not retained or released. Only the objects they are in and in certain situations. Try it without the [img release];

Also that code in the viewdidload should be after the super viewdidload line.
__________________
Questions?

Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
Objective Zero is offline   Reply With Quote
Old 09-19-2011, 06:20 PM   #5 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You shouldn't say they aren't retained or released. UIImages inherit from NSObject just like every class out there. It's just that in this instance, he hasn't retained it so he doesn't need to release it.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 09-19-2011, 07:13 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by VinC_HK View Post
Code:
//In the CameraChooseViewController.m

- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo {
    [picker dismissModalViewControllerAnimated:YES];
	
	SomeEdit* theSomeEditViewController;
	//Create a new view controller or point to an existing one
	
	theSomeEditViewController.imageToShow = image;
	 
	[CameraChooseViewController pushViewController:  theSomeEditViewController animated: TRUE];
	
}
// the SomeEdit.m file
- (void)viewDidLoad {	
	
	UIImage *img;
	if (img != nil) { // Image was loaded successfully.
		[img setImage:imageToShow];
		
		[img release]; // Release the image now that we have a UIImageView that contains it.
	}
	[super viewDidLoad];
}
Here's the update version of it.
but still won't work
Can anyone point out where I go wrong?

This code doesn't make any sense:

Code:
// the SomeEdit.m file
- (void)viewDidLoad {	
	
	UIImage *img;
	if (img != nil) { // Image was loaded successfully.
		[img setImage:imageToShow];
		
		[img release]; // Release the image now that we have a UIImageView that contains it.
	}
	[super viewDidLoad];
}
You create a local variable img. When you create a local variable in a method, the variable doesn't exist until the method is called, and it contains garbage once the method starts running.

Your img local variable will never contain a valid value when viewDidLoad is called. You want to look at the imageToShow property. So, viewDidLoad should look like this:

Code:
// the SomeEdit.m file
- (void)viewDidLoad 
{	
  if (self.imageToShow != nil) 
  {
    //Replace "myImageView" below with the name of your 
    //UIImageView IBOutlet that should display the image.
    [myImageView setImage: self.imageToShow];
		
    //[img release]; NO! DO NOT RELEASE anything here. No need.
  }
  [super viewDidLoad];
}
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-20-2011, 05:32 AM   #7 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 37
VinC_HK is on a distinguished road
Default

thanks for everybody comment but it still doesn't work...

Code:
- (void)viewDidLoad 
{	
	
	if (self.imageToShow != nil) 
	{
		[import setImage: self.imageToShow];
	}
	[super viewDidLoad];
}
/*
but I notice there is one warning
it said that 'CameraChooseViewController' may not respond to '+pushViewController: animated:'

the whole source of the code is
Code:
- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo {
    [picker dismissModalViewControllerAnimated:YES];
	
	
	SomeEdit* theSomeEditViewController;
	//Create a new view controller or point to an existing one
	
	theSomeEditViewController.imageToShow = image;
	 
	[CameraChooseViewController pushViewController:  theSomeEditViewController animated: TRUE];
	
}
VinC_HK is offline   Reply With Quote
Old 09-20-2011, 07:00 AM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by VinC_HK View Post
thanks for everybody comment but it still doesn't work...

Code:
- (void)viewDidLoad 
{	
	
	if (self.imageToShow != nil) 
	{
		[import setImage: self.imageToShow];
	}
	[super viewDidLoad];
}
/*
but I notice there is one warning
it said that 'CameraChooseViewController' may not respond to '+pushViewController: animated:'

the whole source of the code is
Code:
- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo {
    [picker dismissModalViewControllerAnimated:YES];
	
	
	SomeEdit* theSomeEditViewController;
	//Create a new view controller or point to an existing one
	
	theSomeEditViewController.imageToShow = image;
	 
	[CameraChooseViewController pushViewController:  theSomeEditViewController animated: TRUE];
	
}

"it still doesn't work" is not helpful. What happens? Have you stepped through your code and checked that the "import" variable is not nil? Have you checked that imageToShow is not nil? Where is the code that sets the imageToShow property and then displays the view controller?

As for the warning you're getting, it sounds like you're trying to send a pushViewController: animated: message to a view controller. You send that message to your navigation controller, not a view controller. That will crash your program at runtime.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-20-2011, 09:45 AM   #9 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 37
VinC_HK is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
"it still doesn't work" is not helpful. What happens? Have you stepped through your code and checked that the "import" variable is not nil? Have you checked that imageToShow is not nil? Where is the code that sets the imageToShow property and then displays the view controller?

As for the warning you're getting, it sounds like you're trying to send a pushViewController: animated: message to a view controller. You send that message to your navigation controller, not a view controller. That will crash your program at runtime.
This is the code I set my UIImageView *import to UIImage *imageToShow
and it is how I check there is imageToShow is nil or not.
Please point out my mistake.

Code:
- (void)viewDidLoad 
{	
	
	if (self.imageToShow != nil) 
	{
		[import setImage: self.imageToShow];
	}
	else {
		NSLog(@"imageToShow is nil");
	}

	[super viewDidLoad];
}
For the second question, I really don't know how to send the message to a view controller. As you can see, I'm really new to objective c and iphone apps programming.
Is it like this?

Code:
	
	SomeEdit* theSomeEditViewController = [[SomeEdit alloc] initWithNibName:@"SomeEdit" bundle:[NSBundle mainBundle]];
	//Create a new view controller or point to an existing one
	
	theSomeEditViewController.imageToShow = image;
	
	 
	[self.navigationController pushViewController:  theSomeEditViewController
										  animated: TRUE];
	[theSomeEditViewController release];
}
But the imageView is still not the image I choose from the iPhone Library.
It go back to the home page, which is the CameraChoose xib

Last edited by VinC_HK; 09-20-2011 at 10:04 AM.
VinC_HK is offline   Reply With Quote
Old 09-21-2011, 03:28 AM   #10 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 37
VinC_HK is on a distinguished road
Default

any help please?
VinC_HK is offline   Reply With Quote
Reply

Bookmarks

Tags
image, importing

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 395
16 members and 379 guests
7twenty7, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, JackReidy, jarv, n00b, pbart, Pudding, sacha1996, teebee74, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0