2011-11-17 46 views
1

我想添加一些imageViews和tableView到Titanium的scrollView中。我希望scrollView是可滾動的,但不是tableView裏面,所以我將tableView.scrollable設置爲false。但是,即使scrollView的高度超過屏幕的高度,也不可滾動。由於不鼓勵在scrollView中放置tableView,所以我想知道是否有更好的方法在Titanium中的scrollView中創建具有固定長度的表格?如何在Appcelerator Titanium的scrollView中創建固定長度的表格?

下面是我的代碼:

var view = Ti.UI.createScrollView({ 
    contentWidth:'auto', 
    contentHeight:'auto', 
    top:0, 
    showVerticalScrollIndicator:true, 
    showHorizontalScrollIndicator:true, 
}); 

var imageview1 = Ti.UI.createImageView({ 
    image: "../images/headers/gscs_logo.png", 
    height: 80, 
    left: 10, 
    right: 10, 
    top: 10, 
}); 

var imageview2 = Ti.UI.createImageView({ 
    image: "../images/headers/wellness_logo.png", 
    height: 80, 
    left: 10, 
    right: 10, 
    top: 90, 
}); 

view.add(imageview1); 
view.add(imageview2); 

var tableview = Ti.UI.createTableView({ 
    data: [{title:'a'}, {title:'b'}, {title:'c'}, {title:'d'}, {title:'e'}, {title:'f'}, {title:'g'}], 
    top: 180, 
    scrollable: false, 
}); 

view.add(tableview); 

Ti.UI.currentWindow.add(view); 

This是我得到的窗口(StackOverflow上不允許新用戶發佈圖片,抱歉)。

This是我想要的窗口。該表具有固定的行數,並且其父視圖可以滾動。

我也嘗試將currentWindow.layout設置爲「垂直」,但是失敗了,因爲scrollView和tableView都不會顯示出來。

謝謝你的耐心和幫助!

+0

由於觸摸事件不會被正確發送,因此不應該將UITableView添加到UIScrollView。 – msgambel

+0

@MSgambel我知道這並不好,但我想不出一個更好的解決方案。 –

+0

試試這件,它適合我的作品: ------------------------------ [請輸入鏈接描述] [1 ] [1]:http://stackoverflow.com/questions/23242298/how-i-can-add-a-table-view-in-a-scroll-view –

回答

4

看了Kitchen Sink,Titanium的演示程序後,我想出瞭如何做到這一點:只需將tableview.style設置爲Titanium.UI.iPhone.TableViewStyle.GROUPED,然後將imageView設置爲tableview.headerView。

var imageview = Ti.UI.createImageView({ 
    image: "../images/headers/bakerinstitute_logo.png", 
    height: 100, 
    left: 40, 
    right: 40, 
    top: 10, 
}); 

var tableview = Ti.UI.createTableView({ 
    data: [{title:'a', header:'first one'}, {title:'b'}, {title:'c'}, {title:'d'}, {title:'e'}, {title:'f'}, {title:'g'}, {title:'h'}, {title:'i'}, {title:'j'}, {title:'k', header:'last one'}], 
    style:Titanium.UI.iPhone.TableViewStyle.GROUPED, 
    backgroundColor:'transparent', 
    rowBackgroundColor:'white', 
    headerView: imageview 
}); 

Ti.UI.currentWindow.add(tableview); 
-2

您應該查看蘋果提供的UICatalog sample code。有很多意見,其中一些看起來像你提供了一個鏈接。希望有助於!

+0

這是關於鈦,不客觀C –

+1

這仍然是他可以使用的一個例子。 – msgambel

相關問題