滚动时,将搜索栏保留在表格视图的顶部

时间:2014-10-11 17:45:26

标签: titanium titanium-mobile appcelerator

我研究了以下两个问题,都问我到底要问的是什么:

https://developer.appcelerator.com/question/117432/keep-searchbar-at-the-top-of-the-tableview-when-scrolling

https://developer.appcelerator.com/question/10611/adding-table-view-beneath-searchbar

问题是,两个问题都没有得到确认和正确答案。建议使用解决方案,并且后续评论总是说"没有工作"。一个例外,评论说"完美地工作",似乎是指一个根本没有使用搜索栏的答案,而且似乎毫无意义。 因此,即使向下滚动表格行,我也只是在寻找一种保持搜索栏可见的好方法。我的表中有数百行。表加载速度快,行滚动精细,搜索工作完美。唯一的问题(与其他2个帖子相同)是,当您开始在表格中向下滚动时,搜索栏会向上滚动到站点外。我很惊讶,一旦滚动,搜索栏的默认行为就会消失。很难想象有人会想要这种行为。 这是我的代码:

var searchbar = Ti.UI.createSearchBar({
    showCancel: true,
    top: 5
});

var movies = Ti.UI.createTableView({
    data: movieData,
    top: 30,
    height: '75%',
    search: searchbar,
    hideSearchOnSelection: false
});

1 个答案:

答案 0 :(得分:1)

我这样编码: var searchBar = Ti.UI.createSearchBar({         showCancel:false,         borderRadius:10,         borderColor:“#000”,         提示文字:'搜索..',         身高:45,         barColor:“#fff”     });

View.add(searchBar);

var tableView = Ti.UI.createTableView({
    top : searchBar.top + searchBar.height + 30,
    search : searchBar,
    filterCaseInsensitive : true,
    filterAttribute : 'nametoshow',
    backgroundColor : 'transparent',
    separatorStyle : Ti.UI.iPhone.TableViewSeparatorStyle.SINGLE_LINE,
    separatorColor : 'transparent'
});

View.add(tableView);

即使这没有帮助您尝试将zindex添加到搜索栏。更大的zindex组件将使其位于较小的zindex组件上。

相关问题