[Resolved] iOS, Objective-C Declaring Variable to entire Class. - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 17, 2012, 09:56 AM   #1
resetme
macrumors newbie
 
Join Date: Oct 2012
iOS, Objective-C Declaring Variable to entire Class.

Hi guyz,

i'm new here and i have one doubt about creating variables.

I have a variable that get the screen size of the device declared inside a method, but i need it to be out of the scope to all my methods inside the same class (just for the same class).

I dont want to pass it by arguments to every method, so i need a private visible variable for this class.

How can i do that?
Right now i have:

I declared it only in the .m file
Code:
@interface ViewController ()

@end

@implementation ViewController
@synthesize seleccion,button1,button2,button3;

static CGRect screenBound;
static CGFloat screenWidth;
static CGFloat screenHeight;

- (void)viewDidLoad
{

    //Get Screen Size
    screenBound = [[UIScreen mainScreen] bounds];
    screenWidth = screenBound.size.width;
    screenHeight = screenBound.size.height;

   //Lot of methods who use the screen size here 
   bla bla bla

}
It's that correct? i never use static in C#, for me static means visible for ALL class and i dont want that, i just need it for this class. also... it's there a problem for not declaring it at my .h file?

Thanxs!
resetme is offline   0 Reply With Quote
Old Dec 17, 2012, 10:39 AM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by resetme View Post
It's that correct? i never use static in C#, for me static means visible for ALL class and i dont want that
Yes, that's correct. In Objective-C, static does not mean visible for ALL classes.
__________________
dejo is offline   0 Reply With Quote
Old Dec 17, 2012, 02:01 PM   #3
resetme
Thread Starter
macrumors newbie
 
Join Date: Oct 2012
ty!


hey, do u know how to delegate?

i need to call a function in class B from classA when an animation is over.


classA:
Code:
[UIView animateWithDuration:animateDuration
                          delay:animateDelay
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                         CGRect frame = obj.frame;
                         frame.origin.x = posX;
                         frame.origin.y = posY;
                         obj.frame = frame;

                     }
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                         ----> hey CLASS B im DONE do something!
   
                     }
     ];
classB
import classA

-(void)doSomeThing{
}


Srry for asking twice :/
resetme is offline   0 Reply With Quote
Old Dec 17, 2012, 03:40 PM   #4
resetme
Thread Starter
macrumors newbie
 
Join Date: Oct 2012
no problem!

i used protocol and delegate!



Code:
completion:^(BOOL finished){
                         NSLog(@"Done!");
                         if([obj isKindOfClass:[UIButton class]]){
                             [self.delegate animationDone:(UIButton *)obj];
                         }
                     }
resetme is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Any Class Action over iOS 7 on iPhone 4? MacVault iOS 7 120 Jan 26, 2014 08:53 PM
Applescript newb: declaring a variable in another script. Vanilla Face Mac Programming 2 Jan 5, 2014 07:39 PM
new objective C-class won't create .h file OriginalJef iPhone/iPad Programming 2 Mar 3, 2013 03:24 PM
iOS Apps : HTML5 vs Objective-C? msaljaber iPhone/iPad Programming 12 Feb 7, 2013 07:51 PM

Forum Jump

All times are GMT -5. The time now is 06:55 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC