iPhone programming problem about UIView and UIViewController
I am a newbie in iph开发者_StackOverflow中文版one dev, and I am confused by UIViewController.
most program start with a view controller, but I don't know why we need it. ViewController has a view, but you cannot use the drawRect medthod. So why not just use View instead of ViewController in places like UIWindow and so on?
I learned that to initialize a View, you need to use initWithCoder, because view is in the nib file. But why view is in the nib file? I subclass UIView and do some drawing in drawRect, what is its connection with nib file ?
You can open the nib file in Interface Builder so you can build the user interface graphically instead of programatically. So you don't need to drawRect, you can just build your interface through interface builder.
UIViewControllers contain UIViews. Apple believes in Model-View-Controller software architecture, in which the data is separated from the view, but the data and view are joined by a controller class, which handles application logic.
Model < -- > Controller < -- > View
CustomDataClass < -- > UIViewController < -- > UIView
精彩评论