我正在尝试开发一个iMessage应用程序,我不知道如何将值从自定义单元格传递到另一个视图控制器。我需要确保一旦按钮被按下,来自单元格的值就被复制到文本发送空间中。请帮帮我!我被困在这里:
这是iMessage代码,而不是"hello“,它需要从单元格中放置标签文本。
let layout = MSMessageTemplateLayout()
layout.caption = "Hello World"
let message = MSMessage()
message.layout = layout
self.activeConversation?.insert(message, completionHandler: nil) func configureWithContactEntry(_ contact: ContactEntry) {
contactNameLabel.text = contact.name
contactEmailLabel.text = contact.email ?? ""
contactPhoneLabel.text = contact.phone ?? ""
return cell let cell = tableView.dequeueReusableCell(withIdentifier:
"ContactTableViewCell", for: indexPath) as! ContactTableViewCell
let entry = filteredContacts[(indexPath as NSIndexPath).row]
cell.configureWithContactEntry(entry)
cell.layoutIfNeeded()
return cell如果有人能帮我的话就太好了!
发布于 2017-11-17 03:46:18
您可以以这种方式将单元数据传递给imessage扩展中的其他控制器。检查您的单元格选择的覆盖函数,其外观如下
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
print("cell selected at row \(indexPath.row)")
}从您的模型对象获取基于indexPath的模型数据,在您的情况下,您应该从这个函数中获得。
let entry = filteredContacts[(indexPath as NSIndexPath).row]
let name = entry.name然后创建Msession对象并从条目对象中填充其中的数据。
let session = MSSession()
let message = MSMessage(session: session)
let layout = MSMessageTemplateLayout()
layout.caption = name
message.layout = layout
//save the message in the current conversation context
self.savedConversation?.insert(message,
completionHandler: { (err) in
print("ERROR \(err.debugDescription)")
})另外,如果您想在消息中附加图像,那么就这样做吧。
layout.image = UIImage(named:"image.png")!https://stackoverflow.com/questions/47327648
复制相似问题