I have two class ..
in one of them I am using six buttons with their tag..
like this
[btnF1 setTag:1];
and I am using this tag
like this..
- (void)showPhoto:(UIButton*)btnSender {
NSLog(@"showPhoto:%d",btnSender.tag);
}
Now I want to make variable that stores the value of btnSender.tag and I can also use that value in any other class also…
I made two approches..
1) I made a variable in this class which stores btnSender.tag value and I tried to use this value in other class but it is giving me null
2) I tried out the global variable but not able to see the value of the global variable in the NSLog..
I am not using IB
Help me out…:)
You can use NSUserDefaults or UILabel to store the value of button tag. But for using UILabel you will have to Outlet it to a hidden label in your XIB only then it will retain its value.
NSUserDefaults stores the value permanently till you refresh it. So there won’t be a problem of retaining the values.
So better approach is to use
NSUserDefaultsas shown below. May be you can put this on an event (for Example ButtonClick if you are going to next view on a button click.)Now when you go to next view, you can access it using below code:
Hope this helps you.