Swift:inputAccessoryView按钮未显示 [英] Swift: inputAccessoryView buttons are not showing

查看:305
本文介绍了Swift:inputAccessoryView按钮未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Following is my code for adding an inputAccessoryView (with a Done button on it) to my 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

完成"按钮将永远不会出现.我所得到的只是一个白色的附件栏.我在这里想念什么吗?

The Done button never appears. All I get is a white accessory bar. Am I missing anything here?

推荐答案

对我来说,我使用UINavigationBar创建附件视图是这样的:

For me I create the accessory view using UINavigationBar like this:

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

这篇关于Swift:inputAccessoryView按钮未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆