Search code examples
iosswiftnslayoutconstraintsubviewaddsubview

IOS keyboard is blocking the SubView


I have added a subview to my UItableView when No result found. but I have a problem with the portion of "No result found"UIView. it is centre and block by iOS keyboard. how can I fix the layout Constraint?

 if(filteredAccounts!.isEmpty){
            hideSection = true
            view.backgroundColor = UIColor.white
            view.addSubview(noResultView)
            noResultView.center = view.center
            self.hubtableView.reloadData()
            hubtableView.separatorStyle = .none
        }

Noresult found

subView Blocked by keyboard

enter image description here


Solution

  • I believe the table view handles adjusting the view to account for the keyboard. However, since you’re adding a new different view, you’ll have to handle the adjustment yourself.

    However, if the search is nil, you could instead return a single cell instead of adding a view. (Or do something similar with the header view, background view, etc.)