So basically on my ClassA.h I have created a NSNumber called selected. It is also used in @property as well in that .h. Now in ClassA.m I have a table view and when one is selected it goes to another screen. I would like the indexPath.row to save into that NSNumber. (Selected was @synthesized as well in .m)
Where it is being called in ClassA.m is in the didSelectRowAtIndexPath and looks like this.
selected = [NSNumber numberWithInt:indexPath.row];
In the next view is where I would like to recall this code so that it can load a perticular view by code based on the selection. I import ClassA.h and this is the code I put in for ClassB.m
HowTosViewController *h = [[HowTosViewController alloc] init];
if([h.selected intValue] == 0){
content.text = @"0";
}
else if ([h.selected intValue] == 1){
content.text = @"1";
}
I’m assuming my issue is I didn’t store it correctly or it isn’t calling it correctly. I would prefer to do this using the global variables so if there is an easier way to do this using them I wouldnt mind. I appreciate any help.
Also as a side note. When I go to release selected would it cause any problems or be correct if I did it in ClassB? After it loads the screen from using that number it is no longer needed and another one should be assigned if the person goes back and selects another option.
Thanks 🙂
EDIT: Forgot to mention what it is doing currently. Currently when clicking on any of the Cells in ClassA it opens the screen and displays 0.
When you do this in ClassB.m
that is a new instance, not the same instance where you stored your selected value.
Consider init’ing your ClassB with selected value as well and use that in classB like doing
delcare this receivedSelectedIndex like
and where you create instance of ClassB you should do like