NNikN
NNikN

Reputation: 3850

UISearchController add's offset while editing

UISearchController add's a offset when editing begins. In Landscape mode it works perfectly fine, but does not in portrait mode.

Are there any settings in storyboard that can help to overcome this issue.

The following works but, shows a animation which goes at +320 and then brings back to -320.

func updateSearchResultsForSearchController(searchController: UISearchController) {
        self.mySearchContorller.searchBar.frame=CGRectMake(-320, 0, self.myTable.frame.size.width, 44.0)

    }

enter image description here

enter image description here

I have used storyboard with a segue (Show Detail).Attached is a screen shot of the storyboard.

enter image description here

Upvotes: 2

Views: 585

Answers (1)

Yariv Nissim
Yariv Nissim

Reputation: 13343

Downloaded your project and played with it and it seems the problem is here:
Change
self.tblSearchController.definesPresentationContext = true to
definesPresentationContext = true

Also, you're subclassing UITableViewController, don't create your own table but drag one into your storyboard and use it. Here's how your DetailViewController should look like:
class DetailTableViewController: UITableViewController {

var tblSearchController:UISearchController!

override func viewDidLoad() {
    super.viewDidLoad()

    self.tblSearchController = UISearchController(searchResultsController: nil)
    self.tableView.tableHeaderView=self.tblSearchController.searchBar
    definesPresentationContext = true

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let aCell:UITableViewCell! =  tableView.dequeueReusableCellWithIdentifier("Cell")
    return aCell
}

} enter image description here

Upvotes: 1

Related Questions