本文介绍了如何通过iOS中的故事板将UISearchBar添加到NavigationBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在(一个问题 - 一个答案:非常短,所以请查看)。

I find what seems like an elegant answer to this question at How to add search bar in navigation bar for iPhone (one question-one answer: very short so please look).

我喜欢这件作品关于在故事板(也称为IB)中执行此操作:即从NavigationBar titleView创建出口到IB中的SearchBar。但是我会在哪里将SearchBar放在故事板上?

I like the piece about doing it in the storyboard (aka IB): i.e. "create an outlet from the NavigationBar titleView to the SearchBar in IB". But where would I place the SearchBar on the storyboard?

这是我做的:


  • 我在我的TableView标题中删除了SearchBar

  • 然后从NavigatorBar我指向出口到SearchBar作为titleView(唯一选项)

  • 但是当我运行程序时,我遇到了崩溃:以NSException类型的未捕获异常终止

  • I dropped the SearchBar in my TableView header
  • Then from NavigatorBar I point outlet to the SearchBar as titleView (the only option)
  • But when I run the program I get a crash: terminating with uncaught exception of type NSException.

该程序还打开了我的代码

The program also opened my code in

 int main(int argc, char * argv[])
 {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MINAppDelegate class]));
    }
 }


推荐答案

将View(UIView)拖动到导航栏中,然后您可以拖动视图中的几乎任何UI元素,包括UISearchBar。我尝试过并且适合我。

just drag a View (UIView) into navigation bar, then you can drag almost any UI element inside the view, including UISearchBar. I tried it and works for me.

这篇关于如何通过iOS中的故事板将UISearchBar添加到NavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:07