@@ -60,6 +60,19 @@ var Controller = function() {
60
60
/**
61
61
* @method getTopLevelViews
62
62
* Returns a list of the root view elements associated with this controller.
63
+
64
+ * #### Example
65
+ * The following example displays the `id` of each top-level view associated with the
66
+ * controller:
67
+
68
+ // index.js
69
+ var views = $.getTopLevelViews();
70
+ for (each in views) {
71
+ var view = views[each];
72
+ console.log(view.id);
73
+ }
74
+
75
+ *
63
76
*
64
77
* @return {Array.<(Titanium.UI.View|Alloy.Controller)> }
65
78
*/
@@ -72,6 +85,13 @@ var Controller = function() {
72
85
* Returns the specified view associated with this controller.
73
86
*
74
87
* If no `id` is specified, returns the first top-level view.
88
+ *
89
+ * #### Example
90
+ * The following example gets a reference to a `<Window/>` object
91
+ * with the `id` of "loginWin" and then calls its [open()](Titanium.UI.Window) method.
92
+
93
+ var loginWindow = $.getView('loginWin');
94
+ loginWindow.open();
75
95
*
76
96
* @param {String } [id] ID of the view to return.
77
97
* @return {Titanium.UI.View/Alloy.Controller }
@@ -95,6 +115,42 @@ var Controller = function() {
95
115
* @method getViews
96
116
* Returns a list of all IDed view elements associated with this controller.
97
117
*
118
+ * #### Example
119
+ * Given the following XML view:
120
+
121
+ <Alloy>
122
+ <TabGroup id="tabs">
123
+ <Tab title="Tab 1" icon="KS_nav_ui.png" id="tab1">
124
+ <Window title="Tab 1" id="win1">
125
+ <Label id="label1">I am Window 1</Label>
126
+ </Window>
127
+ </Tab>
128
+ <Tab title="Tab 2" icon="KS_nav_views.png" id="tab2">
129
+ <Window title="Tab 2" id="wind2">
130
+ <Label id="label2">I am Window 2</Label>
131
+ </Window>
132
+ </Tab>
133
+ </TabGroup>
134
+ <View id="otherview"></View>
135
+ </Alloy>
136
+
137
+ * The following view-controller outputs the id of each view in the hierarchy.
138
+
139
+ var views = $.getViews();
140
+ for (each in views) {
141
+ var view = views[each];
142
+ console.log(view.id);
143
+ }
144
+
145
+ [INFO] : win1
146
+ [INFO] : label1
147
+ [INFO] : tab1
148
+ [INFO] : wind2
149
+ [INFO] : label2
150
+ [INFO] : tab2
151
+ [INFO] : tabs
152
+ [INFO] : otherview
153
+
98
154
* @return {Array.<(Titanium.UI.View|Alloy.Controller)> }
99
155
*/
100
156
getViews : function ( ) {
@@ -107,9 +163,17 @@ var Controller = function() {
107
163
* UI components. It is critical that this is called when employing
108
164
* model/collection binding in order to avoid potential memory leaks.
109
165
* $.destroy() should be called whenever a controller's UI is to
110
- * be "closed" or removed from the app. For more details, see the
111
- * example app found here:
112
- * https://github.com/appcelerator/alloy/tree/master/test/apps/models/binding_destroy
166
+ * be "closed" or removed from the app. See the [Destroying Data Bindings](#!/guide/Destroying_Data_Bindings)
167
+ * test application for an example of this approach.
168
+
169
+ * #### Example
170
+ * In the following example the view-controller for a {@link Titanium.UI.Window Window} object named `dialog`
171
+ * calls its `destroy()` method in response to the Window object being closed.
172
+
173
+
174
+ $.dialog.addEventListener('close', function() {
175
+ $.destroy();
176
+ });
113
177
*/
114
178
destroy : function ( ) {
115
179
// destroy() is defined during the compile process based on
@@ -154,12 +218,39 @@ var Controller = function() {
154
218
* @method createStyle
155
219
* Creates a dictionary of properties based on the specified styles.
156
220
*
221
+ *
157
222
* You can use this dictionary with the view object's
158
223
* {@link Titanium.UI.View#method-applyProperties applyProperties} method
159
224
* or a create object method, such as {@link Titanium.UI#method-createView Titanium.UI.createView}.
225
+ * #### Examples
226
+ * The following creates a new style object that is passed as a parameter
227
+ * to the {@link Titanium.UI#method-createLabel Ti.UI.createLabel()} method.
228
+
229
+ var styleArgs = {
230
+ apiName: 'Ti.UI.Label',
231
+ classes: ['blue','shadow','large'],
232
+ id: 'tester',
233
+ borderWidth: 2,
234
+ borderRadius: 16,
235
+ borderColor: '#000'
236
+ };
237
+ var styleObject = $.createStyle(styleArgs);
238
+ testLabel = Ti.UI.createLabel(styleObject);
239
+
240
+ * The next example uses the {@link Titanium#method-applyProperties applyProperties()} method
241
+ * to apply a style object to an existing Button control (button not shown).
242
+
243
+ var style = $.createStyle({
244
+ classes: args.button,
245
+ apiName: 'Button',
246
+ color: 'blue'
247
+ });
248
+ $.button.applyProperties(style);
160
249
* @param {AlloyStyleDict } opts Dictionary of styles to apply.
250
+ *
161
251
* @return {Dictionary }
162
252
* @since 1.2.0
253
+
163
254
*/
164
255
createStyle : function ( opts ) {
165
256
return Alloy . createStyle ( getControllerParam ( ) , opts ) ;
@@ -178,7 +269,29 @@ var Controller = function() {
178
269
* @method addClass
179
270
* Adds a TSS class to the specified view object.
180
271
*
181
- * You can apply additional styles with the `opts` parameter.
272
+ * You can apply additional styles with the `opts` parameter. To use this method
273
+ * effectively you may need to enable autostyling
274
+ * on the target XML view. See [Autostyle](#!/guide/Dynamic_Styles-section-37530415_DynamicStyles-Autostyle)
275
+ * in the Alloy developer guide.
276
+ * #### Example
277
+ * The following adds the TSS classes ".redbg" and ".bigger" to a {@link Titanium.UI.Label}
278
+ * object proxy `label1`, and also sets the label's `text` property to "Cancel".
279
+
280
+ // index.js
281
+ $.addClass($.label1, 'redbg bigger', {text: "Cancel"});
282
+
283
+ The 'redbg' and 'bigger' classes are shown below:
284
+
285
+ // index.tss
286
+ ".redbg" : {
287
+ color: 'red'
288
+ }
289
+ ".bigger": {
290
+ font : {
291
+ fontSize: '36'
292
+ }
293
+ }
294
+
182
295
* @param {Object } proxy View object to which to add class(es).
183
296
* @param {Array<String>/String } classes Array or space-separated list of classes to apply.
184
297
* @param {Dictionary } [opts] Dictionary of properties to apply after classes have been added.
@@ -193,6 +306,15 @@ var Controller = function() {
193
306
* Removes a TSS class from the specified view object.
194
307
*
195
308
* You can apply additional styles after the removal with the `opts` parameter.
309
+ * To use this method effectively you may need to enable autostyling
310
+ * on the target XML view. See [Autostyle](#!/guide/Dynamic_Styles-section-37530415_DynamicStyles-Autostyle)
311
+ * in the Alloy developer guide.
312
+ * #### Example
313
+ * The following removes the "redbg" and "bigger" TSS classes from a {@link Titanium.UI.Label}
314
+ * object proxy `label1`, and also sets the label's `text` property to "...".
315
+
316
+ $.removeClass($.label1, 'redbg bigger', {text: "..."});
317
+
196
318
* @param {Object } proxy View object from which to remove class(es).
197
319
* @param {Array<String>/String } classes Array or space-separated list of classes to remove.
198
320
* @param {Dictionary } [opts] Dictionary of properties to apply after the class removal.
@@ -208,6 +330,15 @@ var Controller = function() {
208
330
* removing any applied classes that are not specified.
209
331
*
210
332
* You can apply classes or styles after the reset using the `classes` or `opts` parameters.
333
+ * To use this method effectively you may need to enable autostyling
334
+ * on the target XML view. See [Autostyle](#!/guide/Dynamic_Styles-section-37530415_DynamicStyles-Autostyle)
335
+ * in the Alloy developer guide.
336
+
337
+ * #### Example
338
+ * The following removes all previously applied styles on `label1` and then applies
339
+ * the TSS class 'no-style'.
340
+
341
+ $.resetClass($.label1, 'no-style');
211
342
* @param {Object } proxy View object to reset.
212
343
* @param {Array<String>/String } [classes] Array or space-separated list of classes to apply after the reset.
213
344
* @param {Dictionary } [opts] Dictionary of properties to apply after the reset.
@@ -219,9 +350,41 @@ var Controller = function() {
219
350
220
351
/**
221
352
* @method updateViews
222
- * Applies a set of properties to view elements associated with this controller
353
+ * Applies a set of properties to view elements associated with this controller.
354
+ * This method is useful for setting properties on repeated elements such as
355
+ * {@link Titanium.UI.TableViewRow TableViewRow} objects, rather than needing to have a controller
356
+ * for those child controllers.
357
+ * #### Example
358
+ * The following example uses this method to update a Label inside a TableViewRow object
359
+ * before adding it to a TableView.
360
+
361
+ * View-controller file: controllers/index.js
362
+
363
+ for (var i=0; i < 10; i++) {
364
+ var row = Alloy.createController("tablerow");
365
+ row.updateViews({
366
+ "#theLabel": {
367
+ text: "I am row #" + i
368
+ }
369
+ });
370
+ $.tableView.appendRow(row.getView());
371
+ };
372
+
373
+ * XML view: views/tablerow.xml
374
+
375
+ <Alloy>
376
+ <TableViewRow>
377
+ <Label id="theLabel"></Label>
378
+ </TableViewRow>
379
+ </Alloy>
380
+
381
+ * XML view: views/index.xml
382
+
383
+ <TableView id="tableView">
384
+ </TableView>
223
385
* @param {Object } args An object whose keys are the IDs (in form '#id') of views to which the styles will be applied.
224
386
* @since 1.4.0
387
+
225
388
*/
226
389
updateViews : function ( args ) {
227
390
var views = this . getViews ( ) ;
0 commit comments