iOS 8中的UISearchBar占位符崩溃

时间:2014-09-23 21:59:23

标签: objective-c ios8 uisearchbar xcode6 placeholder

我有一个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

1 个答案:

答案 0 :(得分:2)

我知道这是一个老问题,但如果其他人面临这个问题,这可以解决问题:

UITextField* tfSearchBar = [self.mySearchBar valueForKey:@"_searchField"];
tfSearchBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Artist, Team or City"];

希望有所帮助