Can I define a UIView both in a nib AND programmatically?

Yes, you can interchange XIB-described objects with program-created ones, and you can do programed modifications of an XIB-instantiated object, or you can use an XIB-instantiated object inside a programmed view.

Up vote 2 down vote favorite share g+ share fb share tw.

I realize the question is broad, but I am new to iOS development and any information helps. Thanks! EDIT: I do mean the same view.

Iphone ios view nib link|improve this question edited Jul 7 '11 at 23:23 asked Jul 7 '11 at 22:47Michael656 70% accept rate.

" If so, I can't see a reason for doing that. If you mean, can I define two views, one in IB and one in a nib, sure you can. – Chris Gregg Jul 7 '11 at 22:50.

Yes, you can interchange XIB-described objects with program-created ones, and you can do programed modifications of an XIB-instantiated object, or you can use an XIB-instantiated object inside a programmed view. Basically an XIB just "generates code" (in a backwards sort of way) to instantiate the objects it describes, and once the root view and all of its subviews are created it's indistinguishable from its program-created twin.

1 Actually, a nib is an archive of objects which get de-archived upon load. No code is "generated" but objects are initialized from the archive. – WTP'-- Jul 7 '11 at 23:19 WTP's comment is quite instructive as to the actual question, I think.

A XIB is just an archived copy of the objects, in much the same way that any property list is. The various connections are achieved using ObjC's inherent reflection. So not only is no code generated per XIB, but it's fine to alter the objects once they've been loaded because, once created, they're not inherently different to objects created in any other way.

– Tommy Jul 7 '11 at 23:27 Thanks, Daniel, and WTP for the clarification. So Daniel, if I were to do programmed modifications of a XIB-instantiated object, would I make those modifications in a view controller or a view of the same name? – Michael Jul 7 '11 at 23:29 Yeah, WTP, I was over-simplifying a bit.

The archived image does have to be interpreted somehow, so many of the motions of executing the code occur, but it's not literally generated code. – Hot Licks Jul 8 '11 at 1:39 You can do modifications of the XIB-instantiated object from anywhere (within reason). You just have to keep in mind that the "owning" view controller is the default responder/delegate.

– Hot Licks Jul 8 '11 at 1:41.

Yes, you can mix use of programmatically created and nib loaded resources in any way you like - often the nib will be used to set up a skeleton that code might alter or add more views to.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions