0

如何在我的表格视图中添加一个多行标签,就像这个屏幕中的一样(多任务手势下面的标签): http ://cl.ly/6g0B

4

2 回答 2

1

这实际上是通过创建一个headerView.

headerLabel = Ti.UI.createLabel({
    text: 'line 1'
});

headerView = Ti.UI.createView({
    height: 60
});

headerSection = Ti.UI.createTableViewSection();

headerView.add(headerLabel);
headerSection.add(headerView);
tableView.add(headerSection);

labels您可以向视图添加更多内容并设置相应height的调整。您还需要headerSection使用data.

于 2011-05-12T03:24:51.183 回答
1

您需要将您的 tableview 分组(至少在针对 iOS 设备时)。然后,您创建一个表格视图部分来包含您的行,并且您的多行标签通过其 headerView 属性添加到该部分。

在此处查看 TableViewSection 视图的文档:http: //developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableViewSection-object

一个简单的例子 - 它未经测试抱歉,我目前没有 Mac,但原理是合理的。您创建一个标题视图,创建一个部分,设置部分标题视图,向该部分添加一些单元格,并为您的表格提供一个部分数组:

var tableView = Ti.UI.createTableView({
   style: Ti.UI.iPhone.TableViewStyle.GROUPED
});
var tableData = [];

var multiLineLabelView = Ti.UI.createView();
var line1 = Ti.UI.createLabel({
     text: 'Some text'
});
var line2 = Ti.UI.createLabel({
     text: 'More text',
     top: 20
});
multiLineLabelView.add(line1);
multiLineLabelView.add(line2);

var section = Ti.UI.createTableViewSection({
    headerView: multiLineLabelView,
    height: 40
});

var row1 = Ti.UI.createTableViewRow({
    title: 'Row 1'
});

var row2 = Ti.UI.createTableViewRow({
    title: 'Row 2'
});

section.add(row1);
section.add(row2);

tableData.push(section);
tableView.data = tableData;

需要注意的重要一点是,您只需要一个表 - 在您给出的示例中,行被分组为部分,其中一些具有标题。

于 2011-05-12T11:18:31.057 回答