objective c - programmatically add subviews into a UIView - ios -


i learning interface builder , saw code (self here refers viewcontroller):

[self presentviewcontroller:anotherviewcontroller animated:yes completion:nil]; 

i notice when create subclass of uiviewcontroller, xcode offers option create associated xib file well.

so assume controller knows associated view (by initwithnibname:). , assume view knows controller associated shown file's owner.

here question:

from understanding, uiview , associated controller go together. right trying programmatically create paged scroll view (horizontal scrolling), each page customized collection view. can create view fine. need customized control in each collection view. however, don't have access collection view's controllers never created them in code.

how can create custom view , have view controller of it? thanks!

a uiview not associated uiviewcontroller.

a uiviewcontroller (or should be) associated uiview, although single view controller not have associated same exact view.

in fact, uiviewcontroller's have view property, represents view controlling, , view not readonly--it can changed @ runtime.

if you're creating view controller on storyboard, or creating view controller associated .xib file, can create outlets elements you've drag-and-dropped onto view controller. done opening assistant editor, or double-clicking companion file open in new window, , ctrl+dragging ui element class's @interface section (either in .h or .m file, in cases .m appropriate).

in addition, when we're talking uitableview, uicollectionview, uitextfield, , other ui elements have delegate and/or datasource properties, these can hooked via interface builder.


in addition this, if give ui elements in interface builder unique tags, can reference them using viewwithtag: method on view controller's view. give reference view matching tag sent argument.


finally, if you've not created element in interface building , want create code, tutorial might need. gist of though... instantiate , set view. once view ready, add view controller's view using addsubview: method.


at end of day, no matter method of hooking views up, need @property in @interface section can maintain reference view. , collectionviews/tableviews, it's important set delegate/datasource properties.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -