UISearchBar占位符在iOS 8中崩溃



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

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

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

希望它能帮助

最新更新