0

以下是我将 inputAccessoryView(上面带有完成按钮)添加到我的 textView 的代码:

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

完成按钮永远不会出现。我得到的只是一个白色的配件条。我在这里错过了什么吗?

4

2 回答 2

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
于 2015-05-13T16:04:09.223 回答
0

1)添加自我?self.messageView.inputAccessoryView = 键盘按钮视图

2)您应该能够删除此行:doneButton.possibleTitles = ["Done"] 并将 (title: "done",...) 添加到它上面的行。

3)我有类似的代码,它可能没关系,但是,你可以添加:keyboardButtonView.barStyle = UIBarStyle.Default

于 2015-05-31T19:50:00.417 回答