我正在尝试完成以下操作: 1.我的tableview包含两个静态单元格 2.单元格的初始文本是"选择联系人" 3.弹出一个模态应该有一个联系人选择器 4.用户应选择联系人 5.应更新静态单元格的文本以匹配联系人的姓名
我遇到以下问题。如果我将委托分配给我的tableviewcontroller,我似乎无法使用两个联系人(无需为每个联系人编写单独的函数)。 我非常想要一个返回联系人的函数。
我一直在尝试,这是我能想到的最好的(它是didSelectRowAtIndexPath的部分实现,应该打开一个联系模式。但是,它似乎不遵循代理的功能。< / p>
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
class PeoplePickerDelegate:NSObject, ABPeoplePickerNavigationControllerDelegate {
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {
let firstName: ABMultiValueRef = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue()
let lastName: ABMultiValueRef = ABRecordCopyValue(person, kABPersonLastNameProperty).takeRetainedValue()
println("name is \(firstName) \(lastName)")
}
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecordRef!) -> Bool {
peoplePickerNavigationController(peoplePicker, didSelectPerson: person)
peoplePicker.dismissViewControllerAnimated(true, completion: nil)
return false;
}
func peoplePickerNavigationControllerDidCancel(peoplePicker: ABPeoplePickerNavigationController!) {
peoplePicker.dismissViewControllerAnimated(true, completion: nil)
}
}
var peoplePickerDelegate:PeoplePickerDelegate?
let picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = peoplePickerDelegate
presentViewController(picker, animated: true, completion: nil)
}
任何帮助都会非常感激,我是一个新手并且非常努力地抓住这个。