Frage

I want to create a single person lap timer xib/class and load it twice onto a single View Controller on my Story Board. Each of the two instances will be used to time and compare two persons lap times on a single ViewController.

I have laid out two Container Views side by side within the Story Board View Controller (LapCounterViewController)

I have also created an xib and class files as a single person lap timer ( LapCounterNibViewContainer)

How do I create two instances of LapCounterNibViewContainer and put it inside each of the Container Views

_vc1 = [[LapCounterNibViewController alloc] initWithNibName:@"LapCounterNibViewController"  bundle:nil];
_vc1.view.frame = self.LapCounterFrame1.frame;
//_vc1.delegate = self;

[_LapCounterFrame1 addChildViewController:_vc1];
[_vc1 didMoveToParentViewController:self];
[self.view addSubview: _vc1.view];

enter image description here

enter image description here

War es hilfreich?

Lösung

In the storyboard, you can add two container views to the same view controller and connect them both with the same child view controller by right-click dragging and choosing embed. This created the segue like so:

embed segue screenshot

Click on the segue and give it an identifier. Then, add the prepareForSegue method to your parent view controller, and set some properties for the lap timers separately if you want.

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segueName isEqualToString: @"embedSegueToLapTimerOne"]) {
        LapCounterNibViewController * childViewController = (LapCounterNibViewController *) [segue destinationViewController];
        [childViewController setFoo:bar1];
    }
    if ([segueName isEqualToString: @"embedSegueToLapTimerTwo"]) {
        LapCounterNibViewController * childViewController = (LapCounterNibViewController *) [segue destinationViewController];
        [childViewController setFoo:bar2];
    }
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top