views:

64

answers:

1

hello I am having a application in which one view controller is pushed and when we pop from the pushed controller i do not get the value for the variable

For eg consider there is A controller i n which i am havinh the int variable named Component now i push to B Controller on click event of button from A Controller ,When we are pushed to B view there is Table View and when i select any of the cell i just pass indexpath.row value to the int component and here i print value of component value which is correct , now when its pop to A controller again i print the value of component which comes to be 0(zero) always.. Where am i wrong

A: 

Without seeing any code I would say that you haven't set up a reference to controller A in controller B so when you are calling A.someInt = 5 nothing is happening. Unlink other languages, calling a method on a nil reference just returns nil. It doesn't throw an error.

skorulis
here i am setting reference for controller A in Controller B by alloc ing it and in B controller class when i print value of A.component =[indexPath.row ] , it is correctly printing the value of A.component and when View will Appear Method of A controller when i print the value component it is null ..
mrugen
You shouldn't be allocing a new instance of A. What you're doing is setting the value in the new instance not the old one.
skorulis
ya i tried without allocing the A controller in B but didnt get the value , sorry if my question is too basic
mrugen