1

I'm writing an app where one component is a checklist screen. The checklist has 4 or 5 logical subsections and I want to display each section as a separate view, with the user switching between views with forward and back buttons (and eventually with a swiping gesture event but that's a separate issue).

Currently, I have a UIViewController class for managing the checklist logic, which loads the initial view from a xib. The xib contains all of the 4 or 5 views, and I can currently fairly easily switch between them just by setting up references to all the UIView objects in the UIViewController and calling

[self setView:viewNumberX];

within that class. However, this just abruptly switches the view, and doesn't have the nice iOS-style animation.

The reason I did it this was was because I thought the proper paradigm was to have one UIViewController managing one or several distinct related views - in this case, my one UIViewController is managing all 4 or 5 subviews because they are all parts of the same checklist subject to the same checklist logic. I do notice that there's a presentModalViewController:(UIViewController*)animated:BOOL method defined for UIViewControllers that does allow me the option of animating as I switch views, but this seems to require that I wrap my UIViews in 4 or 5 separate UIViewControllers, which doesn't make sense to me. The individual views don't have their own logic. Is there another way to get this functionality, or am I approaching this the wrong way?

Tneuktippa
  • 1,645
  • 3
  • 15
  • 25

2 Answers2

1

If you are set about not having a UIViewController for each UIView, you can fix the animation bit using beginAnimations:context: and commitAnimations. Basically you use them like this, e.g.:

[UIView beginAnimations:@"animationName" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
                       forView:self.navigationController.view cache:NO];

...<change view>...
[UIView commitAnimations];

Actually, if you are targeting iOS 4, you are required to use animateWithDuration:animations:, but the concept remains the same. Here you will find a code snippet to do the flip with the latter.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
0

If you want to have checklists you can swipe through, you can avoid both gestures and animations by using UIScrollView with pagingEnabled set to YES. Make the scroll view as wide as screen, and make it's contentSize property as wide as screen * number of screens, then place each checklist inside that scrollview with x coordinate being something like padding + PageNumber * 320 (with pageNumber being an int and starting with 0). If you chose this approach I'm here if you need more details or sample code.

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
  • I was looking into UIScrollViews, and did a bit of a mockup example using them (I'm basically learning iOS programming for this project), and the reason I ultimately didn't persue it further was because I found it really, really difficult to arrange subviews within a UIScrollView in Interface Builder. Basically anything that would've appeared off of the initial screen was impossible to manipulate with the mouse, which sort of defeats the purpose of using IB to begin with. – Tneuktippa Aug 10 '11 at 00:07