Skip to content

Commit

Permalink
Fix for issue #7: Fails to search on autocorrect.
Browse files Browse the repository at this point in the history
  • Loading branch information
willhains committed Dec 7, 2014
1 parent 36b9cdf commit e9bda7d
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions code/Dictionary/DictionaryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,47 @@ class DictionaryViewController: UIViewController, UISearchBarDelegate
self.searchBar.becomeFirstResponder()
}

func searchDictionary()
{
// Check if dictionary contains typed word
let searchText = searchBar.text
if UIReferenceLibraryViewController.dictionaryHasDefinitionForTerm(searchText)
{
// Remove the existing dictionary view controller, if it exists
if let refVC = self.referenceViewController
{
refVC.removeFromParentViewController()
refVC.view.removeFromSuperview()
}

// Create the dictionary view controller
let refVC = UIReferenceLibraryViewController(term: searchText)

// Display the dictionary view inside the container view
self.addChildViewController(refVC)
refVC.view.frame = self.dictionaryContainer.frame
self.view.addSubview(refVC.view)
refVC.didMoveToParentViewController(self)

// Remember for later
self.referenceViewController = refVC
}
}

func searchBar(searchBar: UISearchBar, textDidChange searchText: String)
{
// Delay slightly to make typing smoother
Timer("type delay", 1.0)
{
// Check if dictionary contains typed word
let searchText = searchBar.text
if UIReferenceLibraryViewController.dictionaryHasDefinitionForTerm(searchText)
{
// Remove the existing dictionary view controller, if it exists
if let refVC = self.referenceViewController
{
refVC.removeFromParentViewController()
refVC.view.removeFromSuperview()
}

// Create the dictionary view controller
let refVC = UIReferenceLibraryViewController(term: searchText)

// Display the dictionary view inside the container view
self.addChildViewController(refVC)
refVC.view.frame = self.dictionaryContainer.frame
self.view.addSubview(refVC.view)
refVC.didMoveToParentViewController(self)

// Remember for later
self.referenceViewController = refVC
}
self.searchDictionary()
}
}

func searchBarTextDidEndEditing(searchBar: UISearchBar)
{
searchDictionary()
}

func searchBarSearchButtonClicked(searchBar: UISearchBar)
{
// Hide keyboard
Expand Down

0 comments on commit e9bda7d

Please sign in to comment.