在视图控制器中使用段控制实现视图和视图控制器

时间:2017-03-03 07:36:07

标签: objective-c

View中使用ViewController实施segment controlViewController是否有任何解决方案?

我尝试创建ChildViewController并添加它。当我想查看其他View时,我尝试使用View移除removeFromsuperview并移除ChildViewController但是它无效。

- (IBAction)segmentcontrol:(id)sender {
    notificationsViewController *notification=[[notificationsViewController alloc]init];


    if (self.segmentControl.selectedSegmentIndex == 0)
    {

        if(self.view==nil)
        {
            self.attendeesTableView.frame=CGRectMake(0, 64, 320, 416);
            [self.view addSubview:self.attendeesTableView];
        }
        else
        {
            [notification willMoveToParentViewController:nil];
            [notification.view removeFromSuperview];
            [notification removeFromParentViewController];
            self.attendeesTableView.hidden=NO;
        }
    }

    else if(self.segmentControl.selectedSegmentIndex == 1)

    {

        self.attendeesTableView.hidden = YES;
        notification.view.frame=CGRectMake(0, 64, 320, 416);
        [self addChildViewController:notification];
        [self.view addSubview:notification.view];
        [notification didMoveToParentViewController:self];

    }

}

0 个答案:

没有答案