【问题标题】:Titanium create table view replacing existing viewTitanium 创建表视图替换现有视图
【发布时间】:2013-07-14 15:02:20
【问题描述】:

我有一个梦想……不,不是这样。 我有一个视图,在我添加 createTableView 之前一切正常。 当我这样做时,它会替换之前出现在屏幕上的所有内容。 如何同时拥有 mapview 和 tableview?

var self = Ti.UI.createView();

var mapview = Titanium.Map.createView({
    top:1,
    height:200,
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true
});

self.add(mapview);

var lbl = Ti.UI.createLabel({
    text:'Please select an item',
    height:'auto',
    width:'auto',
    color:'#000'
});
self.add(lbl);

self.addEventListener('itemSelected', function(e) {
    lbl.text = e.name+': $'+e.price;
});

detailData = [{title:"Foo",leftImage:"bar.png",hasChild:true}];


var table = Ti.UI.createTableView({
    data:detailData
});
// if i dont rem the below line all i get on screen is the table view
self.add(table);

【问题讨论】:

    标签: titanium tableview


    【解决方案1】:

    TableView 控件通常会占据整个屏幕,我会尝试将 MapView 添加到 TableView 的其中一行,however, this may not work on Android:

    // Create the table
    var self = Ti.UI.createView();
    var detailData = [{title:"Foo",leftImage:"bar.png",hasChild:true}];
    var table = Ti.UI.createTableView({
        data : detailData
    });
    self.add(table);
    
    // Create the mapview
    var mapview = Titanium.Map.createView({
        top:1,
        height:200,
        mapType: Titanium.Map.STANDARD_TYPE,
        region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
        animate:true,
        regionFit:true,
        userLocation:true
    });
    
    // Insert a row in first index of the table that has the mapview in it
    var row = Ti.UI.createTableViewRow();
    row.add(mapview);
    table.insertRowBefore(1, row);
    

    编辑:

    糟糕,更简单的方法是设置表格的高度,并使您的容器视图具有垂直布局:

    // Create the container view
    var self = Ti.UI.createView({
        layout : 'vertical'
    });
    // Add the mapview
    var mapview = Titanium.Map.createView({
        height:200,
    });
    self.add(mapview);
    // Add the table
    var table = Ti.UI.createTableView({
        top : 0,
        data : detailData
    });
    self.add(table);
    

    【讨论】:

    • Curses...有类似的东西可以用吗?
    • 我可以添加某种 html 吗?
    • 尝试编辑,尽管表格视图行方法在 IMO 上效果很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 2010-11-17
    • 2019-01-24
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多