problem after adding a subview on a UITableView

Discussion in 'iOS Programming' started by ashwinr87, Jul 19, 2011.

  1. ashwinr87 macrumors member

    Mar 9, 2011
    In my ipad app, I have a split screen view. In the detail view of the split screen view, I have 6 UITableview subviews.

    On a button click, I am animating a UITableView subview and bringing another view ( say, View A) on top of the UITableView. This is the code I use to bring in View A,

    if (viewA == nil) 
            viewA = [[viewAController alloc] initWithNibName:@"ViewViewController" bundle:nil];
            self.view.userInteractionEnabled = NO;
            [self.view addSubview:viewA.view];
            [UIView transitionWithView:self.view duration:1
                            animations:^ {
                            completion:^(BOOL finished){
    so the problem I am facing here is that, since the view behind View A is a UITableView, if I scroll down on the UITableView and then click on the button, the View A also goes up with the UITableView.

    How can I solve this problem? What is the other way I can bring in the View A?

    It would be great if someone could help me with this.
  2. RonC macrumors regular

    Oct 18, 2007
    When I decode that sentence, I think it means the following:
    A given UITableView subview is currently presented in the detail view (let's call this one tableViewCurrent). Based on what is selected in the root view, a different table view (tableViewNext) will be presented to the user. You want to animate that action of presenting that different table view.​

    Given that as the desire, I'd do the following with your code:
    • Add some actual action code to your animations block as well as the completion block. There's a nice example in the View Programming Guide, listing 4-6, that covers it pretty well. The easiest thing is probably to just change the hidden state of tableViewCurrent and tableViewNext so that one becomes hidden and the other becomes visible, and when the animation is done make tableViewCurrent point at tableViewNext (since it is now "current").
    • As for the current section/row that's being presented, you can pretty easily reset the newly presented table view an index path (like 0,0) by using scrollToRowAtIndexPath:atScrollPosition:animated: with animated=NO; you could do this in the completion block, but doing it before the animation might make more sense.

Share This Page