Pergunta

I'm trying to develop some reusable ViewController classes.

I usually have a two tableViews in on ViewController in my older viewControllers (pre iOS5).

I'm planning a rewrite and I was thinking about using the new iOS 5 containment APIs, Consider this example:

Ideally, i would use two viewcontrollers, each ViewController having 2 tableViews. At anypoint either ViewController would essentially show 2 tableViews.

I was wondering if I should: Use 4 ViewControllers, each having a tableView, add those to a ParentContainerView. Arrange them in my previous order.

The problem would be, to be able to show two ViewControllers at the same time in a divided manner, change the behaviour of A viewController when a sliding gesture is IN PROGRESS.

To reflect sliding gestures:

i really cant seem to figure out how to reflect the swiping gestures down to the child view controllers and influence the sliding behaviour of the viewcontroller. Any example would be great. Forexample, ViewController at index 0 would reduce in width before disappearing to the left when a right swipe gesture is in progress a new ViewController at index 2 appears, all while the middle ViewController (index 1) changes its yposition and not its width.

ANy suggestions would be great,

Foi útil?

Solução

I don't know if this is what you want, but I've implemented something like this using a scroll view with four container views in the scroll view's content view. Each of those container views has an embedded segue to a view controller (would be a tableViewController in your case).

So this is how I did it:

  1. I added a scroll view to my view controller
  2. I dragged in a UIView onto the scroll view and set its frame to {{0,0},{640,548}}
  3. Added 4 container views underneath the view from step 2 (by underneath, I mean underneath the view in the objects list on the left side of the screen. It was easier to do it this way since the view doesn't show its full width on the canvas). I set their frames to {{0,0},{160,548}} {{160,0},{160,548}} {{320,0},{160,548}} and {{480,0},{160,548}}. This gives you four view controllers, each half the width of the screen.
  4. Added another full size view under the scrollview (under in the list, but that means on top in the view hierarchy) and made its background color clear. This view sits on top and intercepts all the touches.
  5. Added 2 swipe gesture recognizers (one left on right) to the view from step 4.

In the view controller, I created IBOutlets to the scroll view (scroller) and to the large (the 640 x 548 one) view (content), and added this code in the .m file:

@implementation ViewController

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.scroller.contentSize = self.content.frame.size;
}

-(IBAction)moveLeft:(id) sender {
    if (self.scroller.contentOffset.x < 320)
        [self.scroller setContentOffset:CGPointMake(self.scroller.contentOffset.x + 160, 0) animated:YES];
}

-(IBAction)moveRight:(id) sender {
    if (self.scroller.contentOffset.x > 0)
        [self.scroller setContentOffset:CGPointMake(self.scroller.contentOffset.x - 160, 0) animated:YES];
}

@end

The 2 gesture recognizers were connected in IB to the moveLeft: and moveRight: methods. So, this gives me the ability to show controllers 1&2, 2&3, or 3&4 on the screen at the same time.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top