2015-05-13 46 views
0

以下是我用於添加inputAccessoryView(上有一個完成按鈕)到我的TextView代碼:斯威夫特:inputAccessoryView按鈕沒有顯示

let keyboardButtonView = UIToolbar() 
keyboardButtonView.sizeToFit() 
let doneButton = UIBarButtonItem(image: nil, style: .Done, target: self, action: "closeMessageViewKeyboard") 
doneButton.possibleTitles = ["Done"] 
var toolbarButtons = NSMutableArray() 
toolbarButtons.addObject(doneButton) 
keyboardButtonView.items = toolbarButtons as [AnyObject] 
messageView.inputAccessoryView = keyboardButtonView 

單擊完成按鈕將永遠不會出現。我得到的只是一個白色的配件吧。我在這裏錯過了什麼嗎?

回答

2

對我來說,我創建一個使用UINavigationBar的這樣的附屬視圖:

let navBar = UINavigationBar(frame: CGRectMake(0, 0, viewWidth, 44)) 
navBar.barStyle = UIBarStyle.BlackTranslucent; 
navBar.backgroundColor = UIColor.blackColor(); 
navBar.alpha = 0.9; 
//replace viewWidth with view controller width 
let navItem = UINavigationItem() 
let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "closeMessageViewKeyboard") 
navItem.rightBarButtonItem = doneButton 

navBar.pushNavigationItem(navItem, animated: false) 

messageView.inputAccessoryView = navBar 
+0

這並不顯示inputAccessoryView可言。 – Kashif

+0

檢查更新的代碼。我忘了把框架或UINavigationBar –

+0

現在我看到一個白色的酒吧在鍵盤上,但沒有按鈕。 – Kashif

0

1)添加的自我? self.messageView.inputAccessoryView = keyboardButtonView

2)你應該能夠刪除這一行: doneButton.possibleTitles = 「完成」] 並添加(標題: 「完成」,...)到線它上面。

3)我有類似的代碼,它可能並不重要,但是,您可以添加: keyboardButtonView.barStyle = UIBarStyle.Default