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 06-10-2011, 07:08 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
adityamatharu is on a distinguished road
Red face Using Variables in a method Help (Weak fundamentals!!)

Hi all

I am very new to obj-C programming and have little experience in other OOP languages. I have some basics which I draw upon to understand code.

I am making a small 'training' iphone project to teach myself Obj-C/iphone sdk through practice and I am kind of stuck.


Basically what my program is:

Step 1.
I have a main view controller with an UIImageView *imageview instance variable, a generic button 'trybutton' (I will explain its function in following step) and a button to open the 'photolibrary' modally and select a photo and display it as imageview.image = selectedimage. Where selectedimage is the variable that UIImagePicker stores the selected image. Then I dismisses the modal view.


Step 2.
Back on the main view controller, I can now see the selected image and then I press the other button 'trybutton' and another modal view 'Name' pops up. This modal view 'Name' has a button on it called 'Done'


Step 3
This done button is linked to a method:

Code:
-(IBACTION) donebtnpressed:(id)sender
{
[self someMethod:imageView.image];
}

What I want this 'Done' button, which exists on the modal view controller 'Name' is to take the imageView.image from the main view controller and pass it onto a method 'someMethod' that takes a UIImage as a parameter input.


But when I try this, when the method -(IBACTION) donebtnpressedid)sender is called the imageView.image is empty and hence my 'someMethod' fails to give me the desired output.


Being a noobie. I cant work out how to have the imageView.image available to donebtnpressed method.


Can you please help? What I am thinking is I maybe need to store the contents of selectedimage in a variable that is available to all methods to access in the .m file. But I dont know how to do that. Am I looking to create a static variable?


Any help will be greatly appreciated.
adityamatharu is offline   Reply With Quote
Old 06-10-2011, 04:56 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
adityamatharu is on a distinguished road
Default

Ok. Just tried using a static variable in the class and it seems to work (so far). So my recommendation to anyone who has a similar issue is to try a static variable.
adityamatharu is offline   Reply With Quote
Reply

Bookmarks

Tags
basics, image, static, variables

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: 314
7 members and 307 guests
chemistry, Dnnake, iOS.Lover, jenniead38, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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