What is included in the view and what happens in the view controller?

I am new to programming for the iPhone, and this will be my first question. I have experience working with different languages ​​such as php / java / C ++.

My question is about ViewControllers and views in iOS.

I started a project that will contain several different things, such as the login screen, the main screen, and several other screens. The goal of this project is to learn how to create everything programmatically, and not use the interface designer to get used to the system. I am using the book: “Advanced iOS 4 Programming” to help me.

I managed to create all the screens (and things like logging-in work), but I'm not sure if I did it right.

All my code for creating text fields / labels / buttons is now in the ViewController, while the main view, where everyone is wearing, is almost empty and nothing is done in it. Should the code for creating text fields and other components be in the view itself or is this the right approach?

I looked at several different examples, but most use an interface constructor. The book itself is also not very clear on this issue.

Thanks in advance.

Regards, Jasper

+4
source share
2 answers

In your view , you have a look - in other words, literally what a person sees with his own eyes.

So, for example, if you are making a complex drawing, you will have your own drawRect: method, and, for example, is in the view.

On the other hand......

There are things in the view controller that control the view .

Generally speaking, "everything" is included in the view controller.

When you first start programming for the iPhone (or Mac), just put everything in the view controller and don't worry too much. There is a lot to learn. Ok

Finally, highlight the “actual drawing” separately in the view.

We hope this simple explanation for beginners helps!

+3
source

In a simple controller code, there should be methods such as ...

class myLoginController : NSObject { UIView *myView; } -(void) initLoginController -(void) loadLoginViewInView :(UIView*)inView; -(void) removeLoginView; -(void) isViewLoaded; -(void) submitButtonClicked : (id) button; -(BOOL) isLoginSuccess; 

and initLoginController you can create your own view,

 -(void) loadLoginViewInView :(UIView*)inView { [inView addSubview:myView]; } 

and in removeLoginView you can remove "myView" from your supervisor.

+1
source

Source: https://habr.com/ru/post/1341449/


All Articles