How To Access Values Of BOOL, CGFloat, Etc. From Another Class?

Discussion in 'iOS Programming' started by Darkroom, Sep 5, 2009.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    so in my SomeRandomClass i have a boolean called someRandomBool. i'm attempting to access the current value of said bool thru AnotherClass:

    Code:
    #import <UIKit/UIKit.h>
    @class SomeRandomClass;
    
    @interface AnotherClass : UIViewController
    	{
    	SomeRandomClass *someRandomClassInstance;
    	}
    
    @property (nonatomic, retain) IBOutlet SomeRandomClass *someRandomClassInstance;
    
    @end
    
    -=-=-=-
    
    #import "AnotherClass.h"
    #import "SomeRandomClass.h"
    
    
    @implementation AnotherClass
    
    @synthesize someRandomClassInstance;
    
    - (void)loadView
    	{
    	if (someRandomClassInstance.someRandomBool == YES)
    		NSLog(@"Bool Is YES");
    		else
    		NSLog(@"Bool Is NO");
    	}
    @end
    
    ... doesn't work.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Where do you set the value of someRandomClassInstance?
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    i connect it to a proxy object in IB
     
  4. eddietr macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #4
    A proxy object or an actual object?
     
  5. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    it's a UITableViewCell subclass ("AnotherClass") accessing a UIViewController class ("SomeRandomClass") thru a proxy object.

    i fail to see where this is going...
     
  6. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #6
    because usually and what works is if you have
    SomeClass *instanceOfClass
    in the .h
    then in the viewDidLoad you would have
    instanceOfClass = [[SomeClass alloc] init];
    then you can do
    if ([instanceOfClass someBool])
    // code if its set to true


    And people are asking to try and understand what you have done instead

    Also what errors are you getting?
    are they build time errors or run time errors?
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Is someRandomClassInstance set to the correct value when this line is executed?:
    Code:
    if (someRandomClassInstance.someRandomBool == YES)
     
  8. eddietr macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #8
    Just trying to figure out the circumstances here.

    So is your proxy being resolved correctly? Is someRandomClassInstance equal to nil by any chance?
     
  9. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #9
    i'm officially an idiot... officially... really, it's official.

    the problem was that i hadn't set properties on the boolean variables, so the instance of the class couldn't access them...

    thank you for all your help.
     

Share This Page