带有自定义行的 Titanium TableViewRow 类名

标签 titanium tableview allocation classname

我想知道 Ti.UI.TableViewRow 的“className”属性在创建自定义行时有何帮助。

例如,我通过以下方式使用自定义行填充表格 View :

function populateTableView(tableView, data) {
  var rows = [];
  var row;
  var title, image;
  var i;

  for (i = 0; i < data.length; i++) {
    title = Ti.UI.createLabel({
      text : data[i].title,
      width : 100,
      height: 30,
      top: 5,
      left: 25
    });
    image = Ti.UI.createImage({
      image : 'some_image.png',
      width: 30,
      height: 30,
      top: 5,
      left: 5
    });

    /* and, like, 5+ more views or whatever */

    row = Ti.UI.createTableViewRow();

    row.add(titleLabel);
    row.add(image);

    rows.push(row);
  }

  tableView.setData(rows);
}

当然,使用 TableViewRow 的标准 titleimage 属性可以轻松创建这个“自定义”行示例,但这不是重点。如何防止 TableView 的新标签、 ImageView 和其他 subview 的分配以利于它们的重用?我知道在 iOS 中,这是通过使用方法 -[UITableView dequeueReusableCellWithIdentifier:] 从当前不是的“reservoir”(因此“className”在这里是“identifier”)获取行对象来实现的用于显示数据,但已经在其中正确布局了所需的 subview ,因此只需要更新其中包含的数据(文本、图像数据等)。

由于这个系统非常简单,我很难相信 Titanium API 使用的方法不支持这一点。

在阅读 API 并搜索网络后,我确实怀疑情况确实如此。建议使用“className”属性作为在 Titanium 中提高 TableView 效率的简单方法,但它与自定义 TableView 行的关系没有以任何方式解释。如果有人能为我澄清这个问题,我将非常感激。

最佳答案

Titanium SDK 使用 -[UITableView dequeueReusableCellWithIdentifier:] 来重用单元格布局。在 UITableView 代理(Titanium SDK 2.1.3)中,您有以下内容:

TiUITableView.m(第 1720 行)

- (UITableViewCell *)tableView:(UITableView *)ourTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    UITableViewCell *cell = [ourTableView dequeueReusableCellWithIdentifier:row.tableClass];
    ...
}

此代码用于重用布局单元。这个方法的更多内容可以查看here ,在 Apple 文档中。

关于带有自定义行的 Titanium TableViewRow 类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10969535/

相关文章:

javascript - Appcelerator Titanium(合金)- 打开另一个包含新窗口的 Controller

javascript - 修改合金项目中的小部件

ios - 在联系人详细信息窗口中选择电子邮件属性后显示邮件编辑器时,Titanium 应用程序崩溃

ios - 选中单元格时如何更改单元格的高度?

c++ - 函数的堆栈分配

c - 使用临时数组的动态内存分配

titanium - Facebook 登录无法正常工作 - 节点类型上不存在字段(AnonymousUser)

javafx-2 - JavaFX,如何卡住TableView中某些列的位置

swift - fatal error : Index out of range when updating data source of table

c - 在程序中计算标量积的第一个 'for' 循环之后,第二个 'for' 循环被忽略