PDA

View Full Version : problem after adding a subview on a UITableView




ashwinr87
Jul 19, 2011, 10:39 AM
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
options:UIViewAnimationOptionTransitionFlipFromRight
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.



RonC
Jul 19, 2011, 01:13 PM
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.

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.