开发者

Access Data in the navigation controller

I have a controller1 which contains a view which contain many subviews ( Textfields,....). I use a navigation controller. I push the controller1 and in this controller I push an other controller2.

My problem is to access the data of the controller1, for example I want to access the data of the textfield of my controller1 in the controller2.

How I can do this please ???

Thanks for your answe开发者_JAVA技巧rs


As you are using navigation controller you will have access of all the viewcontrollers you pushed on navigation stack. You can retreive any one of them using following code.

[[self.navigationController viewControllers] objectAtIndex:<Here you need to take care of the correct index of your desired viewcontroller>]; 

//above code will return viewcontroller at that index.

for knowing correct index, use

NSLog(@"View Controllers : \n%@\n",[self.navigationController viewControllers]];

Thanks,


By controller1 and controller2, I'll assume that you mean UIViewController. If that is what you mean, than just create IBOutlets of the objects that you want to access in the first UIViewController. Then #import the first UIViewController in your second UIViewController and then you can access the IBOutlets from there.

Next time please search as this is a fairly common question and has been answered numerous times all over the internet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜