Ios 在单元格中显示contact.phoneNumber
您好,我目前正在处理一个联系人应用程序,无法在单元格中正确显示联系人号码,我只想显示为一个没有可选文本和(“”)的字符串。这是我的密码:Ios 在单元格中显示contact.phoneNumber,ios,swift,uitableview,contacts,Ios,Swift,Uitableview,Contacts,您好,我目前正在处理一个联系人应用程序,无法在单元格中正确显示联系人号码,我只想显示为一个没有可选文本和(“”)的字符串。这是我的密码: let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath) let contact: CNContact! if inSearchMode { contact = filteredData[indexPath.r
let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
let contact: CNContact!
if inSearchMode {
contact = filteredData[indexPath.row]
} else {
contact = contactList[indexPath.row]
}
cell.textLabel?.text = "\(contact.givenName) \(contact.familyName) \((contact.phoneNumbers.first?.value as? CNPhoneNumber)?.stringValue) "
return cell
}
如何在名称下显示数字?使用此?
运算符:
"\(contact.givenName ?? "") \(contact.familyName ?? "") \((contact.phoneNumbers.first?.value as? CNPhoneNumber)?.stringValue ?? "") "
举个例子:
let s: String? = "Hello"
let newString = s ?? "World" //s is not nil, so it is unwrapped and returned
type(of: newString) //String.Type
如果?
左侧的操作数为nil,则返回其右侧的操作数。??
左侧的操作数不是nil,然后将其展开并返回
let s2: String? = nil
let s3 = s ?? "World" //In this case s2 is nil, so "World" is returned
type(of: newString) //String.Type
谢谢,效果很好。如何在名称下显示它?使用相同的运算符,我正在更新答案谢谢您的示例。现在,我如何在第二行返回它?您的意思是希望它作为描述?您必须设置单元格的样式,使其具有详细信息标签,或者在情节提要中,或者您应该使用
CNContactFormatter
显示联系人的姓名。