简体   繁体   中英

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 answers

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.

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM