Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27123

How to switch between different UIViewcontrollers

I want to write a custom switch that will be located two custom tabBar. Its structure is as follows - enter image description here

I want to use uiviewcontroller.

Now I use the following code:

- (void)changeViewController:(NSInteger)sender{

    if(viewController){
        [viewController.view removeFromSuperview];
        [viewController release];  
        NSLog(@"released");
    }

    switch (sender) {
        case 1:      
            viewController = [[VC1 alloc] init];
            break;
        case 2:
            viewController = [[VC2 alloc] init];
            break;
        case 3:
            viewController = [[VC3 alloc] init];
            break;

        default:
            break;
    }

    [viewController.view setFrame:CGRectMake(0, 100, 320, 380)];
    [self.view addSubview:viewController.view];

}

but I think it's wrong!

Can be used in such a structure - presentModalViewController, dismissModalViewControllerAnimated or other method to work on the similarity navigationViewController?

Upvotes: 2

Views: 1171

Answers (2)

rahul gupta
rahul gupta

Reputation: 396

Try this

[self.navigationController pushViewController:viewController animated:YES];

or

[self.view addsubview:viewcontroller.view];

Upvotes: 2

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73588

You could try this - [self.navigationController pushViewController:viewController animated:NO];

or [self.navigationController popToViewController:targetController animated:YES];

I would really subscribe navigationController for its memory management and a far responsive and seamless behaviour...

hope this helps.

Upvotes: 0

Related Questions