我有一个隐藏在ViewDidLoad上的集合视图。当用户点击搜索栏时,会显示集合视图。但是当我单击搜索栏中的取消按钮时,集合视图不会被隐藏。我在其他帖子上阅读使用.alpha = 0隐藏视图并且有效。我的问题是:
以下是代码:
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
collectionView.isHidden = true // This doesn't work
//collectionView.alpha = 0 // This works
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
collectionView.isHidden = false // This doesn't work
//collectionView.alpha = 1 // This works
return true
}
感谢您阅读我的问题。
答案 0 :(得分:0)
这个隐藏属性在 let device_mappings = datatable(device_id:long, columns_output:string)[
123, "ABC",
123, "GHI",
121, "ABC",
121, "DEF",
122, "LMN"];
let dt = datatable(device_id:long,TIME:datetime,ABC:long,DEF:long,GHI:long,LMN:long)
[123,datetime(2021-04-20 00:00:00.0000000),1,2,3,4,
123,datetime(2021-04-21 00:00:00.0000000),10,20,30,40,
121,datetime(2021-04-20 00:00:00.0000000),1,2,3,4,
122,datetime(2021-04-20 00:00:00.0000000),1,2,3,4];
let func = view(id:long) {
let idKeys = toscalar(device_mappings | where device_id == id | summarize make_set(columns_output));
let otherKeys = toscalar(device_mappings | where device_id != id | summarize make_set(columns_output));
let keysToRemove = set_difference(otherKeys,idKeys);
dt
| where device_id == id
| extend rec = pack_all()
| project filteredRec = bag_remove_keys(rec, keysToRemove)
| evaluate bag_unpack(filteredRec)
};
func(123)
上效果最好(同时用于许多其他事情)。如果您想使用隐藏属性,最好将您的 UIView
嵌入视图中。
该属性的默认值为 false。作为优化, 当值取值时,集合视图可能不会创建相应的视图 这个属性是真的。因为可能没有视图,隐藏 元素不参与集合视图的命中测试。
来源:https://developer.apple.com/documentation/appkit/nscollectionviewlayoutattributes/1535336-ishidden