0

I have the schema like that:

----- main view    
       |
        ---right bar view
             |
              ----- Navigation Controller view
                     |
                     ------tableView Controller

how can i remove the right bar view from the window when i'm on tableViewController?

fizampou
  • 717
  • 2
  • 10
  • 29

2 Answers2

0

Try this:

 [self.view.superview.superview removeFromSuperview];

Another approach, much cleaner, would be using notifications: you could send a notification to the object controlling your main view, so that it removes it right bar subview. It would be something like:

In your main view controller:

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(removeRightBar:) 
    name:@"RemoveRightBarNotification"
    object:nil];


- (void) receiveTestNotification:(NSNotification *) notification
{
     <REMOVE SUBVIEW FROM mainView>
}

and in your table view controller:

[[NSNotificationCenter defaultCenter] 
    postNotificationName:@"RemoveRightBarNotification" 
    object:self];

In this case notification will provide a very loose connection between the main view and the table view controller.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • If I did not understand correctly your question, maybe some more details are needed... what do you mean by "remove the right bar view"? what are you trying to do? – sergio Oct 18 '12 at 12:06
  • i have the main screen and a helper bar on the right i want to remove that helper bar when a button tapped! – fizampou Oct 18 '12 at 12:16
  • that actually worked needed some customization [self.view.superview.superview.superview.superview removeFromSuperview]; But it's not that pretty – fizampou Oct 18 '12 at 12:20
  • @Filippos Zampounis: please see my edit for a more elegant way of doing it. – sergio Oct 18 '12 at 12:36
0

Use tag to the view you are going to delete and remove the view with the reference of that tag.
like:
Before adding the Right Bar View to the main view (self.view) add a tag

rightBarView.tag   =   1;

and for deleting the pirticular view write

for(UIView *temp in [self.view subviews]) {
    if (temp.tag == 1) {
        [temp removeFromSuperview];
    }
}

hope this will help.

x4h1d
  • 6,042
  • 1
  • 31
  • 46
  • that's what i tried but didn't work so i had to add something like that before the for loop http://stackoverflow.com/questions/3843411/getting-reference-to-the-top-most-view-window-in-ios-application – fizampou Oct 18 '12 at 15:47
  • thanks a lot really nice solution but the hard time was to find the view on the screen self.view didn't help a lot! – fizampou Oct 18 '12 at 15:48