我的观点包含导航栏,A UISegmentedController ,其中包含两个段" A"和" B"。默认情况下它有" A"选中,旁边显示tableview
。现在点击" B" tableview
会将y位置增加20,相应地计算高度,并显示searchBar
。
如果用户再次选择" A"然后隐藏搜索栏,tableview
y位置将减少20,高度也会相应计算。在不同的段之间切换时工作正常。现在,当用户用户选择" A"段和现在如果我导航到另一个视图并返回,则表格视图的Y位置增加20。
我的viewWillAppear
不包含任何代码,此外我还没有实现除viewWillAppear
之外的任何与视图相关的方法。任何人都可以帮我解决这个问题吗?
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
//Calling function that will insert static data to tableview
self.settingStaticData()
//Calling function that would customize Search bar
self.customizingSearchBar()
//For detecting whether searching is enabled or not
boolisSearching = false
//By setting default selected segment value to 0
intSelectedSegmentId = 0;
self.displayRequestview()
}
func displayRequestview(){
dispatch_async(dispatch_get_main_queue()) {
self.searchBar?.hidden = true
self.tblSuggestions?.frame = CGRectMake(0,0,(self.tblSuggestions?.frame.size.width)!,(self.tblSuggestions?.frame.size.height)!+44.0)
print("in Request View Height \((self.tblSuggestions?.frame.size.height)!)")
}
//Reloading data
self.tblSuggestions?.reloadData()
self.tblSuggestions?.setContentOffset(CGPointZero, animated:true)
}
func displaySuggestionView(){
dispatch_async(dispatch_get_main_queue()) {
self.searchBar?.hidden = false
self.tblSuggestions?.frame = CGRectMake(0,44.0,(self.tblSuggestions?.frame.size.width)!,(self.tblSuggestions?.frame.size.height)!-44.0)
//print("After Height \(self.tblSuggestions?.frame.size.height)")
}
//Reloading data
self.tblSuggestions?.reloadData()
self.tblSuggestions?.setContentOffset(CGPointZero, animated:true)
}
@IBAction func segmentValueChanged(sender: AnyObject){
let segmentedControl: UISegmentedControl = sender as! UISegmentedControl
if(segmentedControl.selectedSegmentIndex == 0){
print("Height Before Change \((tblSuggestions?.superview?.bounds.height)!)")
intSelectedSegmentId = 0
displayRequestview()
}
else if(segmentedControl.selectedSegmentIndex == 1)
{
intSelectedSegmentId = 1
displaySuggestionView()
}
}
答案 0 :(得分:0)
转到XIB或Storyboard文件
检查'顶栏'&两个视图的“状态栏”设置A&乙
由于状态栏,正在添加/删除20个点。
希望它会解决。