How to load multiple views on each button tap when

2019-09-09 22:55发布

I have a UISegmentedControl with a 3 button layout that I use to control a 3 Views layout that I have I am able to detect the taps on each button but how to I load and show the views that I want for each view

They have to be loaded 1 time and shown upon the tap of the ID of the UISegmentedView

It's a edit-save situation with multiple pages..

1条回答
干净又极端
2楼-- · 2019-09-09 23:42

Use the selectedSegmentIndex property of the UISegmentedControl object.

if (segmentedControl.selectedSegmentIndex == 0) {
    NSLog(@"segment 1");
    if (view1 == NULL) {
        view1 = [[UIViewController alloc] init];
        [self.view addSubview:view1.view];
    }

    else {
        [self.view bringSubviewToFront:view1.view];
    }
}

else {
    NSLog(@"segment 2");
    if (view2 == NULL) {
        view2 = [[UIViewController alloc] init];
        [self.view addSubview:view2.view];
    }

    else {
        [self.view bringSubviewToFront:view2.view];
    }
}
查看更多
登录 后发表回答