2012-10-09 56 views
0

在我的應用程序中,我開發了一種本地語言的自定義鍵盤。現在,這個鍵盤可以很好地處理UITextField和UITextView.For這兩個我實現這樣的自定義鍵盤。如何使用UISearchBar實現自定義鍵盤?

textField.inputView = Customkeyboard; 
textView.inputView = Customkeyboard; 

但是,當我爲的UISearchBar

searchBar.inputView = Customkeyboard; 

實施其其給我下面的錯誤。

error: object cannot be set - either readonly property or no setter found

我還設置其屬性和合成,卻無力解決這一problem.Can任何一個可以幫助我解決這個problem.Thanx。

回答

0

UIResponder

The value of this property is nil. Responder objects that require a custom view to gather input from the user should redeclare this property as readwrite and use it to manage their custom input view. When the receiver subsequently becomes the first responder, the responder infrastructure presents the specified input view automatically. Similarly, when the view resigns its first responder status, the responder infrastructure automatically dismisses the specified view.

好類的文檔,創建繼承的UISearchBar像下面的.h和.m文件的類。在您的.h文件中的廣告如下因素線

@interface SearchBar : UISearchBar
@property (readwrite, retain) UIView *inputView;
@end

在你的電流控制器,你正在使用此,有搜索欄取代的UISearchBar。

searchBar.inputView = Customkeyboard; // Where searchBar is an object of SearchBar and not UISearchBar

+0

是的,當你說它不是你的時候你是正確的,因此你需要添加上面的行。您需要添加上面的行來根據文檔 –

+0

提供此信息否否您還沒有自定義搜索欄。你需要繼承這個搜索欄。就像我上面所做的那樣,然後做你所做的事 –

+1

更新我的代碼 –

0

您將無法設置它的搜索欄,從UIResponder都UITextFieldUISearchBar繼承它具有財產的UIView爲只讀,但覆蓋的UITextField的財產,使它readAndWrite,但搜索欄沒有。

你當然可以創建一個UISearchBar的子類並重新聲明屬性,它可以可能的工作。

+0

感謝名單,以便快速響應,要是你給的電子郵件地址,然後我想分享代碼,BCZ這個問題擊中了我lot.thanx – NSCool

+0

沒有太多吧,你只需要繼承它,並宣告重新聲明屬性爲@property(readwrite,retain)UIView * inputView ;,就像SP指出他的答案一樣。 –

+0

plz檢查此鏈接http://stackoverflow.com/questions/12843523/customkeyboard-implemention-with-uisearchbar – NSCool