-3

I'll just show the example it's easier than words.

.h file

@interface Something : UITableViewController <UIAlertViewDelegate, GADBannerViewDelegate>
{
    NSNumber *myNumber;
}

.m file

-(void) someMethod1
{
NSLog @("is it reaching here? %@", myNumber);
/// returns Null

}

-(void) someMethod2
{

FixturesObject *closestObject;
NSTimeInterval closestInterval = DBL_MAX; 
for (FixturesObject *myObject in newFixtureObjectArray) {
   if (myObject != nullValue) {
    NSTimeInterval interval = ABS([myObject.date2 timeIntervalSinceDate:[NSDate date]]);
    if (interval < closestInterval) {
        closestInterval = interval;
        closestObject = myObject;
    }
    }
        roundFinder = closestObject.round;
        NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
        [f setNumberStyle:NSNumberFormatterNoStyle];
        myNumber = [f numberFromString:roundFinder];
}
NSLog(@"What is my number? %@", myNumber); 
// this returns like.. 26

}

How do i pass the value from the method below to another method? It's not working for me at all.

Thank you for your time.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 3
    This is kinda what parameters are for. (Please learn basic programming before you take up Objective-C. I don't mind you wasting your own time, but you'll waste lots of ours as well.) – Hot Licks Apr 07 '14 at 17:42
  • 1
    Please show where you're calling someMethod1 and someMethod2 from. Is someMethod1 called after someMethod2 and using the same instance of `Something`? –  Apr 07 '14 at 17:53
  • i want to be able to do a slog in someMethod1 for myNumber and get the same value that i get inside someMethod2 – user3504848 Apr 07 '14 at 18:51
  • @user3504848, Ok, so update your question according to my comment (a bit of the code where you call each method and answer the question in the comment). You need to make sure both methods are called using the _**same instance**_ of the view controller object. –  Apr 07 '14 at 18:59

2 Answers2

0

myNumber is part of the same object where you have the methods. You don't need to pass it anywhere. You just need to create a property setter/getter.

Black Frog
  • 11,595
  • 1
  • 35
  • 66
  • 2
    Why would having accessors help? Ivars are accessible inside an object's own methods... – jscs Apr 07 '14 at 17:59
  • Adding the setter/getter methods for myNumbers is not necessary. But OP might want to access it from another object. Since the OP is a newbie, adding the properties using @property is a good exercise for him/her. – Black Frog Apr 07 '14 at 18:37
0

The method you are sending the number has to be able to accept the number as parameter, something like this:

-(void) someMethod1:(NSNumber*)number{

    if (number) NSLog @("is it reaching here? %@", myNumber);
    /// returns Null

    }

But in this case, have a look at what @Black Frog told you. You don't really need to pass this one as it is "all around".

Marcal
  • 1,371
  • 5
  • 19
  • 37
  • It would be more easier to understand if you could explain which problem are you facing. – Marcal Apr 07 '14 at 18:49
  • I am doing some math to get a number inside a parseXML method, then this number is stored inside a NSNumber variable, then inside viewDidLoad i wanna retrieve that number that is stored inside the parseXML method. – user3504848 Apr 07 '14 at 18:58
  • So this NSNumber comes from another VC? – Marcal Apr 07 '14 at 19:24