shabista JD
shabista JD

Reputation: 115

Hide and Unhide masterView from button press of detailView

I know this question has asked by many users,But i did not found any answer related to my issue.

I'm using UISplitViewController ,my application starts with login page, so i have hidden masterView on start, after some time on DetailViewController i shown the master viewController using Delegate method.

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation NS_AVAILABLE_IOS(5_0)
{
    return hideMaster;
}

i have initialised hideMaster to NO ,and my ViewDidLoad() of DetailViewController is below

ViewDidLoad(){

[self.splitViewController.view setNeedsLayout];
    self.splitViewController.delegate =Nil;
    self.splitViewController.delegate = self;

    [self.splitViewController willRotateToInterfaceOrientation:[UIApplication    sharedApplication].statusBarOrientation duration:0];
    [super viewDidLoad];
}

it worked fine my master is now unhide.But on the same detailViewController i have a Back Button on which i'm poping the current ViewController to last viewController and again i want to hide masterViewController my code for back button is below.

- (IBAction)back:(id)sender {




hideMaster = NO;

self.splitViewController.delegate =Nil;
self.splitViewController.delegate = self;

[self.splitViewController willRotateToInterfaceOrientation:[UIApplication    sharedApplication].statusBarOrientation duration:0];


   [self.navigationController popViewControllerAnimated:NO];
}

Its poping the CurrentViewController to last ViewController but its not Hiding the masterViewController

Please help me out.

Upvotes: 2

Views: 247

Answers (2)

user3346502
user3346502

Reputation: 33

you are using UISplitViewController inside your app,since you have many views but whole app is not using UISplitViewController only one view using it.

Its better to use another approach.

Upvotes: 1

Wali Haider
Wali Haider

Reputation: 1272

@JohnD,I went through your code.you are hiding the master view controller while poping the last View controller,but the viewController to which you are navigating is still showing the master View controller.therefore your masterView is still there.

follow the steps given below.

1.make delegate of UInavigationController to that ViewController which is your last singleView controller.

2.In last single ViewController(which is delegate of UINavigationController) implement following delegate method.

  - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[self.splitViewController.view setNeedsLayout];
    self.splitViewController.delegate =Nil;
    self.splitViewController.delegate = self;

    [self.splitViewController willRotateToInterfaceOrientation:[UIApplication    sharedApplication].statusBarOrientation duration:0];
}

3.Now implement delegate method of UISplitViewController in side lastViewController which is given below.

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation NS_AVAILABLE_IOS(5_0)
{
    return hideMaster;<<===============I'm assuming hide master as a variable of shared object(Singleton).
}

4.Now change your - (IBAction)back:(id)sender method with following one.

- (IBAction)back:(id)sender {




hideMaster = Yes;




   [self.navigationController popViewControllerAnimated:NO];
}

I hope this will work,if you stuck some where please let me know.

Upvotes: 2

Related Questions