viewSetupChildrenScript()

Creating Children Dynamically

To create children dynamically, you modify the stepChildren array in your viewSetupChildrenScript. For example, imagine an application which wants to display a number of rows in an overview. The number of displayable rows depends on the height of the overview, which depends on the height of the application view, which in turn depends on the size of the screen. Rather than statically determining the number of children at compile time, the decision can be delayed until run-time when the screen size is known. Here is a viewSetupChildrenScript for a template which creates just the right number of children:

func()
begin
   inherited:?viewSetupChildrenScript();

   local overviewHeight := :LocalBox().bottom;
   local rowTemplate := GetLayout("child");
   local rowHeight :=rowTemplate.viewBounds.bottom;
   local numRows := overviewHeight div rowHeight;
   self.stepChildren :=Array(numRows, rowTemplate);
end;
This code creates a stepChildren array slot in the overview view. Each entry in the array points to the "child" template.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996