简体   繁体   中英

How to pass data to containerview based on segmented control

I have the following setting, my ViewController has a segmented Control with 4 segments and two containerviews A and B with corresponding ViewControllers.

If the first segment is selected the containerView A is showed and B is hidden. If one of the other three is selected, B is shown and A hidden and the selected index is passed to the destination view controller of B using the prepareForSegue method. I want to handle the remaining cases there since only a plot will change in these 3 segments.

I thought I only need one viewcontroller for the 3 latter segments. But if the SegmentedControl changes, the prepare for segue method is not called anymore and I can't handle the different cases in the ViewController of B.. any ideas how to solve this?

I already tried to manually call the segue if the segmented control changed but that did not work.

Use this method:

-[segmentedControl addTarget:self
                 action:@selector(segmentTapped:)
       forControlEvents:UIControlEventValueChanged];

The UISegmentedControl object is passed as a target to the selector you choose, and you can then get the selected index off of that, and update your VC's accordingly.

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