updateSearchResultsForSearchController不能使用UIViewController

时间:2015-12-26 10:48:32

标签: ios swift2

我跟随this tuto 但我想在 Live Photos&上添加搜索栏。信息分段控制,然后将搜索到的字词重定向到实时照片信息视图。
我尝试了搜索栏和搜索显示控制器但由于需要表视图而失败。
然后我尝试了搜索栏并尝试使用此功能获取搜索到的单词:

//MARK: - UISearchBarDelegate
func updateSearchResultsForSearchController(searchController: UISearchController)
{
    print("Looking for \(searchController.searchBar.text!)")
}

但它仍然不起作用 有人已经有这个问题吗?

编辑@rptwsthi和@ katleta3000:
以下是我的代表:UIViewController,UISearchBarDelegate,UISearchDisplayDelegate,UISearchResultsUpdating

我这样设置:

@IBOutlet var searchBar: UISearchBar!
override func viewDidLoad() {
  super.viewDidLoad()
  searchBar.delegate = self
}

更新:
这非常有效:

func searchBarSearchButtonClicked( searchBar: UISearchBar)
{
        print("Looking at \(searchBar.text!)")

}

当我按下返回 searchBarSearchButtonClicked 时会执行但是当我只输入密钥时 updateSearchResultsForSearchController 没有被执行,所以我不认为这是由于委托。

1 个答案:

答案 0 :(得分:1)

似乎func searchBar(searchBar: UISearchBar, textDidChange searchText: String)仅适用于 TableView 仅限查看 FActive:=True; NameThreadForDebugging('FileNotifier '+AnsiString(FDirectory)); while not Terminated do begin GetQueuedCompletionStatus(FChangeCP, numBytes, completionKey, FPOverlapped, INFINITE); if completionKey<>0 then begin if not ReadDirectoryChanges(FDirectoryHandle, @FNotificationBuffer, SizeOf(TdwsFileNotifierBuffer), (FMode=dnoDirectoryAndSubTree), FNotifyFilter, @FBytesWritten, @FOverlapped, nil) then Terminate; fileOpNotification:=@FNotificationBuffer; repeat offset:=fileOpNotification^.NextEntryOffset; if Assigned(FOnFileChanged) then begin notify:=True; for i:=0 to High(FIgnoredPaths) do begin if StrLComp(@fileOpNotification^.FileName[0], PWideChar(Pointer(FIgnoredPaths[i])), Length(FIgnoredPaths[i]))=0 then begin notify:=False; Break; end; end; if notify then begin SetString(fileName, fileOpNotification^.FileName, fileOpNotification^.FileNameLength div SizeOf(Char)); FQueue.QueueNotification(fileName, fileOpNotification^.Action); end; end; fileOpNotification:=@PAnsiChar(fileOpNotification)[offset]; until offset=0; FBytesWritten:=0; FillChar(FNotificationBuffer, 0, SizeOf(TdwsFileNotifierBuffer)); end else Terminate; end; FActive:=False;