0

I am a newbie in iphone 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 ?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

the NSObject near DataClass is misleading since even UIViewController and UIView are NSObjects
You're right! I edited my answer, I hope it no longer misleads.
Thank you for the information! Although I think UIViewController shouldn't contain a view by itself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.