删除UITabBarViewController中的所有控件(子视图)

时间:2014-12-28 09:43:09

标签: objective-c ios8

我对ios编程很新,我最近遇到了一个问题。我正在尝试以编程方式导航到tabbarviewcontroller的选定选项卡。进入选定的选项卡后,删除其中的所有控件并使用不同的控件重新填充它。

我设法以编程方式导航到所选标签,但是,我无法删除所有子视图。

以下是我的代码片段..

- (IBAction)btnSave:(id)sender {
            orthoPaedicInjuryTabBarViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OrthoInjuryTabBarVC"];
            orthoPaedicInjuryTabBarViewController.selectedIndex = 2;
            [self presentViewController:orthoPaedicInjuryTabBarViewController animated:YES completion:nil];
            self.alert = [[UIAlertView alloc] initWithTitle:@"Empty Field, Step3"
                                                    message: @"Please fill up the frequency of exercises"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];

            [self.alert show];

}




   - (void)viewWillAppear:(BOOL)animated {
    Store *MyStore = [Store SharedStore];
    OrthoInjury *orthoInjury = MyStore.orthoInjury;

    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"dd-MM-yyyy"];
    NSString *Dob = [format stringFromDate:orthoInjury.dateOfInjury];

    self.lblDateOfInjury.text= Dob;

    // Do any additional setup after loading the view, typically from a nib.
    self.typeOfExercisesList  = [Utility GetTypesOfExercisesList];

    self.pickerViewTypesOfexercises.dataSource = self;
    self.pickerViewTypesOfexercises.delegate = self;

    TherapyPhases *therapyPhases = MyStore.therapyPhases;
    self.tbxNumberOfWeeks.text = @(therapyPhases.durationWeeks).stringValue;

    if([[orthoInjury.natureOfInjury uppercaseString] isEqualToString:[@"Repetitive Strain Injury" uppercaseString]])
    {
    NSArray *subArray =  [self.view subviews];
    if([subArray count] != 0) {
        for(int i = 1 ; i < [subArray count] ; i++) {
            [[subArray objectAtIndex:i] removeFromSuperview];
            /*if ([[subArray objectAtIndex:i] isKindOfClass:[UILabel class]])
            {
                NSLog(@"%@",[[subArray objectAtIndex:i] text]);
            }*/
        }
    }
    }
}

1 个答案:

答案 0 :(得分:0)

请尝试以下删除子视图: -

NSMutableArray *subVws=[self.tabBarController.view.subviews mutableCopy];
[subVws performSelector:@selector(removeFromSuperview)];