UIView vs UIViewController

后端 未结 3 858
[愿得一人]
[愿得一人] 2020-12-02 17:11

Ok so i am realllly new to the iphone development and i\'ve gotten pretty far for my knowledge. I just need help deciding how to program these 4-6 pictures into my project.

相关标签:
3条回答
  • 2020-12-02 17:43

    A UIViewController cannot display anything; it simply coordinates the display of a UIView. So the actual pictures are going to need to be done in a UIView. In addition, your UIView is responsible for recognizing touches, gestures, etc. That's where it ends, though; the actual reaction of your program should be up to the UIViewController.

    In other words, you'd teach a UIView subclass how to recognize a swipe to the left or right, and once it had decided that a swipe had taken place, it would notify your UIViewController subclass of that event. The controller would then decide what picture would be displayed next, and tell the view to set it up.

    This is part of the Model-View-Controller pattern. It's a well-known and widely-used pattern in iPhone development, so you'd be well served to read up on it.

    0 讨论(0)
  • 2020-12-02 17:48

    The pictures need to be added (via addSubview) to a UIView object or an object subclassed from UIView such as UIControl, UIScrollView, etc.

    You probably do NOT need to create a view class of your own, e.g., MyView. I have found that the only real reason to create a custom view is for efficiency or for highly dynamic content such as text or images that move around within the view. If you don't plan to implement the function drawRect, don't bother with a custom view.

    You will want to subclass the UIViewController. It will manage your view's behavior, and is (usually) the best place to compose the view that it controls.

    UIPageControl is probably the easiest way to implement the swiping behavior, but it can be tricky -- read the documentation carefully.

    0 讨论(0)
  • 2020-12-02 18:04

    You will use both. Cocoa Touch development follows the MVC (Model, View, Controller) methodology. It is a way of separating code logic and user interface elements. UIView is where you handle what it looks like, UIViewController is the class where you handle events. If you want the easiest way to swipe through many pages of content, look into the UIPageControl.

    0 讨论(0)
提交回复
热议问题