我有一个自定义键盘,我想在当前活动的EditText中插入符号⏺。我用这个:
func contactDetail () {
var myPhValue:NSString!
var myPBfirstname:NSString!
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
let addressBook : ABAddressBookRef? = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
ABAddressBookRequestAccessWithCompletion(addressBook, { (granted : Bool, error: CFError!) -> Void in
if granted == true {
let allContacts : NSArray = ABAddressBookCopyArrayOfAllPeople(addressBook).takeRetainedValue()
for contactRef:ABRecordRef in allContacts { // first name
myPBfirstname = ABRecordCopyValue(contactRef, kABPersonFirstNameProperty)?.takeRetainedValue() as! NSString? ?? ""
let myPBlastname = ABRecordCopyValue(contactRef, kABPersonLastNameProperty)?.takeRetainedValue() as! NSString? ?? ""
let phonesRef: ABMultiValueRef = ABRecordCopyValue(contactRef, kABPersonPhoneProperty)?.takeRetainedValue() as ABMultiValueRef? ?? ""
var phonesArray = Array<Dictionary<String,String>>()
for var i:Int = 0; i < ABMultiValueGetCount(phonesRef); i++ {
let myPhLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i)?.takeRetainedValue() as NSString? ?? ""
myPhValue = ABMultiValueCopyValueAtIndex(phonesRef, i)?.takeRetainedValue() as! NSString? ?? ""
if myPhLabel.containsString("Mobile") {
}
}
let nameString = " "+(myPBlastname as String)
let nameValues = (myPBfirstname as String)+(nameString as String)
let contactDict : Dictionary = ["name": nameValues,"phone":myPhValue]
self.contactArray.addObject(contactDict)
if self.contactArray.count == 0 {
NSLog("contactValue is Zero")
}
else{
NSLog("count Value %d", self.contactArray.count)
}
}
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.contactTable.hidden = false
self.contactTable.reloadData()
})
})
})
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return contactArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell = self.contactTable.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.textLabel!.text = contactArray.valueForKey("name").objectAtIndex(indexPath.row) as? String
return cell
}
但是这只插入一个空格(没有可见的字符)。我认为Android不支持所有unicode字符,但是有没有办法插入这个符号?
答案 0 :(得分:0)
为什么不在java代码中尝试以下两个选项:
editText.setText("\u23FA");
或
editText.getText().append("\u23FA");
让我知道你是怎么做到的?