Reputation: 6795
A quick question from a wanna-be iOS developer. I want to create a UI for an iPhone app without Interface Builder, only programmatically. However, I want to stick to MVC recommendations and separate V and C and have a clean readable code, therefore:
Is this a correct approach to begin with?
Second part of the question, independent of Y/N answer to the first. Where do I define these custom UI elements? - Inside the view's initWithFrame: method? - In separate (property getter? property setter?) methods? I.e. do I have to declare each UI element as a property first in the .h file?
If these questions sound a bit ignorant, it must be because they are :) I found lots of sample code on StackOverflow, but little to indicate where you actually put it. I would be really grateful for any help, especially if you could paste/reference some relevant code.
Upvotes: 2
Views: 2086
Reputation: 318774
Your list is correct. This is how I do all of my apps. No Interface Builder, just code.
Each custom view typically creates its own subviews in an appropriate initXXX
method. This could be initWithFrame:
but you could define others as needed. Subview layout can be done through constraints, autoresizing masks, or by implementing layoutSubview
.
Each view controller would instantiate its needed views in the viewDidLoad
. View layout can be done with constraints, autoresizing masks, or by implementing viewWillLayoutSubviews
.
The use of properties is completely optional. Create public properties for anything to be set/get from an outside class. Optionally create private properties for values internal to the implementation.
Upvotes: 2
Reputation: 70135
Go to the Apple website for Sample Code; download everything that you can for applications that are similar to your goal.
Upvotes: 0