1

I dont understand this yet. If I create an ivar of a class (no property). I set the ivar directly to for example @"patrik" in the - (void)viewDidLoad then the ivar value is still there when I click a button and checks for the Ivar value in the handler.

BUT! If I have two buttons. I set the ivar directly in the first button handler that I fire with a click. And then I check the Ivar in the second button handler that i fire. Then the ivar i empty?

Can someone explain what is happining?

Here is the code. Dead simple:

- (void)viewDidLoad
{
   Ivar=@"Patrik";      
   [super viewDidLoad];
}



- (IBAction)secondButtonHandler: (id)sender{

   NSString *result=Ivar;

}


- (IBAction)firstButtonHandler: (id)sender{


}

Here the Ivar is still here when I press the second button.


- (void)viewDidLoad
{

   [super viewDidLoad];
}



- (IBAction)secondButtonHandler: (id)sender{

   NSString *result=Ivar;


}


- (IBAction)firstButtonHandler: (id)sender{

   Ivar=@"Patrik";      
}

But here its not after I have pressed the first button and then the second!?

4

0 回答 0