开发者

Can I link UIView controls (e.g. UILabel, UIPickerView) direct to model instance variables?

Background - Normally with basic UIViewControllers I'm across how you can create instance variables marked as IBOutlet's, and link these to the actual view controls wit开发者_Python百科h Interface Builder.

Question - If I pass a model object to a UIViewController, is there a way to link the View controls (e.g. UILabel, UIPickerView etc) directly to the model variables (i.e. effectively instance variables in a custom class)?

That is this way as soon as the user changes the UI control it would instantly update the model attributes. Assuming you've passed the model to the controller as pass-by-reference, therefore you've automatically updated the values for the parent as a result.

I'm thinking this would avoid having to (a) at initialisation translate the model values to set the UI components, and (b) when finishing up with the view having to manually update the model variables from the UI components.


Like onnoweb states, I don't think there's any way you could do this automatically - mainly because Obj-C would never know what types of variables you were actually looking for. However, you can (and I emphasis this), make your model control your view by letting your model have a view as a property.

Considering Obj-C is built on a MVC-architecture, I wouldn't advice it, though. Let your controller do the work. If you set triggers correctly, this shouldn't be a big problem.


I don't think Obj-C has the concept of property binding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜