The same type of objects with different values when passed as a data source, why not redelivered view?

Exploring Swiftui, I had some things I do not understand.

 

I've created a container view, it can acquire data display, as described herein, but I do not totally change the object rendering referenced in the view, but simply load some of its properties.

 

View of a container loader is observed to be an observation target. When the loader indicates that the value has changed, it will reload the container Body view attributes and data with the new render view. However, when the object to load a class, not all child views the Body property will be re-loaded.

 

When the loader loads the properties of the object, it will use that object to call again passed @viewbuilder closure, but now it's properties are loaded.

 

If you add a print statement, I clearly see included @viewbuilder closure is invoked twice: once using objects unloaded, the first use of the loaded object. These are the same object, but the second loaded the property.

 

Text label (1) has been properly updated, changed from "text is waiting ..." is the actual title, but the object is rendered view (2) does not update its child views.

 

Init using the new data call ObjectRenderingView, but never visited the Body property. This shows me that, Swiftui believe the data has not changed, do not need to re-send.

 

I think I understand why it does not work: obj identity has not changed, so swiftui saw no need to reload objecrenderingview. Since the identification obj.title values ​​from nil to change the actual title, so the text view will be reloaded. I can not understand is how to make Swiftui reload ObjectRenderingView.

If the value is not value semantics, it is not updated behavior in any view of the results of binding the specified use.

 

Guess you like

Origin www.cnblogs.com/gamecenter/p/11291241.html