Ios 使用标记隐藏子视图
在swift中,我可以给出一个视图和一个标签Ios 使用标记隐藏子视图,ios,swift,Ios,Swift,在swift中,我可以给出一个视图和一个标签 let MY_CUSTOM_TAG = 123 tableView.tag = MY_CUSTOM_TAG 我的问题是,如何使用swift从superview中删除带有标记的视图 目标C示例: #define MY_CUSTOM_TAG 1234 mySubview.tag = MY_CUSTOM_TAG; [self.tableView addSubview:mySubview] ; //remove view with tag [[
let MY_CUSTOM_TAG = 123
tableView.tag = MY_CUSTOM_TAG
我的问题是,如何使用swift从superview中删除带有标记的视图
目标C示例:
#define MY_CUSTOM_TAG 1234
mySubview.tag = MY_CUSTOM_TAG;
[self.tableView addSubview:mySubview] ;
//remove view with tag
[[self.tableView viewWithTag:MY_CUSTOM_TAG]removeFromSuperview] ;
与Objective-C相同,只是语法不同
view.viewWithTag(tag).removeFromSuperview()
对于那些来这里寻找隐藏子视图解决方案的人 目标-C:
[[self.view viewWithTag:MY_CUSTOM_TAG] setHidden: YES];
self.view.viewWithTag(viewWithTag:MY_CUSTOM_TAG)?.hidden = true
Swift:
[[self.view viewWithTag:MY_CUSTOM_TAG] setHidden: YES];
self.view.viewWithTag(viewWithTag:MY_CUSTOM_TAG)?.hidden = true
因为标题问的是如何隐藏子视图,而不是如何删除它