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 12-05-2010, 03:23 PM   #1 (permalink)
Try This At Home
 
Gweetle's Avatar
 
Join Date: Nov 2010
Location: Planet Earth
Posts: 208
Gweetle is on a distinguished road
Question Set BOOL from another class?

I would like to set the bool reloadGame to NO from a class that is different from where it is initialized.
In Mode1View.h I have
Code:
	BOOL reloadGame;
@property (nonatomic) BOOL reloadGame;
and I synthesize it and use it in Mode1View.m, but in another class ChangeViews.m I would like to change the value of it to NO;
In ChangeViews.m I have:
Code:
		#import "Mode1View.h"
...
		Mode1View *v1=[[Mode1View alloc] init];
		v1.reloadGame=NO;
Why isn't that setting Mode1View's reloadGame bool to NO?

Thanks
-Gweetle
__________________
Gweetle is offline   Reply With Quote
Old 12-05-2010, 03:33 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You have to understand that what you are doing there is creating a new object of the ModelView type class and settings its value.

There are different ways to approach this but it depends on your code structure. Is ModelView a viewcontroller, what aboutChangeViews too? One way would be to make the ModalView a singleton, that way only one instance of the object will exist, and the code you used would work. The other, if your ModelView controller loads the ChangeViews controller, it could pass the pointer to the object to it, so ChangeViews could access the object that way.
baja_yu is offline   Reply With Quote
Old 12-05-2010, 03:35 PM   #3 (permalink)
Try This At Home
 
Gweetle's Avatar
 
Join Date: Nov 2010
Location: Planet Earth
Posts: 208
Gweetle is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
You have to understand that what you are doing there is creating a new object of the ModelView type class and settings its value.

There are different ways to approach this but it depends on your code structure. Is ModelView a viewcontroller, what aboutChangeViews too? One way would be to make the ModalView a singleton, that way only one instance of the object will exist, and the code you used would work. The other, if your ModelView controller loads the ChangeViews controller, it could pass the pointer to the object to it, so ChangeViews could access the object that way.
Mode1View is a view, with a seperate view controller for it, and changeViews is a view controller. How would I make Mode1View a singleton?
__________________
Gweetle is offline   Reply With Quote
Old 12-05-2010, 03:40 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Here are a few tutorials on the subject:

Singleton pattern - Wikipedia, the free encyclopedia
The Objective-C Singleton

But note that the class you do this for will only be able to have one object. Each time you create (alloc init) an object from that class, it will point to the same object. Used where appropriate it is a very useful design pattern.
baja_yu is offline   Reply With Quote
Old 12-05-2010, 03:43 PM   #5 (permalink)
Registered Member
 
Eagle11's Avatar
 
Join Date: Aug 2009
Age: 20
Posts: 197
Eagle11 is on a distinguished road
Default

The reason that isn't working is because you are creating another instance of the class. You need to access the existing instance. If your appDelegate owns the class, then you can use the appDelegate to get access it.

Code:
AppNameAppDelegate *appDelegate = (AppNameAppDelegate *)[[UIApplication sharedApplication] delegate];

	// Use the app delegate to access theClass
	AppNameAppDelegate *appVC = appDelegate.theClass;
	
        // Set the variable named Variable
	[theClass setVariable:FALSE];
__________________
Work Tracker
Eagle11 is offline   Reply With Quote
Old 12-05-2010, 04:01 PM   #6 (permalink)
Try This At Home
 
Gweetle's Avatar
 
Join Date: Nov 2010
Location: Planet Earth
Posts: 208
Gweetle is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Here are a few tutorials on the subject:

Singleton pattern - Wikipedia, the free encyclopedia
The Objective-C Singleton

But note that the class you do this for will only be able to have one object. Each time you create (alloc init) an object from that class, it will point to the same object. Used where appropriate it is a very useful design pattern.
Thanks a lot! Was able to get it to work, added you to list of awesome people, and now I know how to do it in the future
__________________
Gweetle is offline   Reply With Quote
Reply

Bookmarks

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: 388
7 members and 381 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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