【发布时间】:2015-04-06 22:03:10
【问题描述】:
我以编程方式有一个 UISearchBar 并且可以工作,但是如果我尝试设置占位符并用户点击以搜索我的应用程序崩溃的内容。这是我的代码:
属性
@property (strong, nonatomic) UISearchBar *mySearchBar;
实施
self.mySearchBar = [[UISearchBar alloc] init];
self.mySearchBar.delegate = self;
self.mySearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.mySearchBar.translucent = NO;
self.mySearchBar.returnKeyType = UIReturnKeySearch;
self.mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.mySearchBar.inputAccessoryView = toolBarKeyboard;
self.mySearchBar.placeholder = @"Artist, Team or City";
当用户在 uisearchbar 中点击以查找某些数据时,此行会导致崩溃
self.mySearchBar.placeholder = @"Artist, Team or City";
其他人有此错误?
我用:
- Xcode 6
- iOS 8
- iPhone 5 / 5s
【问题讨论】:
-
这是错误:-[SearchViewController _searchController]: unrecognized selector sent to instance 0x7a09f0f0
-
SearchViewController是你的班级吗?您的班级是否尝试访问_searchController属性/ivar?显示该代码。 -
是的,SearchViewController 是我的课程,我创建了一个 UISearchBar 类似字符串属性并将其添加到导航栏中:self.navigationItem.titleView = self.mySearchBar;
-
这不是我问的。你有任何使用
_searchController值的代码吗? -
嗨,对不起。是的,我发现了错误。我没有注释此代码以控制 uisearchbar 的 uitextfield: UIView *viewToGetClearButton = [self.mySearchBar.subviews objectAtIndex:0]; for (UIView *view in viewToGetClearButton.subviews) { if ([view isKindOfClass: [UITextField class]]) { UITextField *txt = (UITextField *)view; txt.delegate = 自我;休息; } } 我只是删除了这段代码就可以了!
标签: objective-c ios8 uisearchbar xcode6 placeholder