[英]MFMessageComposeViewController in a UITableView (Swift)
I'm trying to show an MFMessageComposeViewController from within a custom TableViewCell class but I get an error saying: "Multiple inheritance from classes UITableViewCell and UIViewController." 我试图从自定义TableViewCell类中显示MFMessageComposeViewController,但出现错误消息:“从类UITableViewCell和UIViewController继承了多个继承。” I know that UIViewController is required for MFMessageComposeViewController, so how can I go about fixing this? 我知道MFMessageComposeViewController需要UIViewController,那么我该如何解决呢?
My code: 我的代码:
class TableViewCell: UITableViewCell, MFMessageComposeViewControllerDelegate {
var userNumber: String!
@IBAction func callButton(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(userNumber)")!)
}
@IBAction func textButton(sender: AnyObject) {
let message = MFMessageComposeViewController()
message.body = ""
message.recipients = ["\(userNumber)"]
message.messageComposeDelegate = self
}
func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
}
You indeed need a UIViewController
to present a MFMessageComposeViewController
. 您确实需要一个UIViewController
来呈现MFMessageComposeViewController
。 To solve your problem, you can add a property to your TableViewCell
: 为了解决您的问题,您可以向TableViewCell
添加一个属性:
var viewController: UIViewController?
You need to assign the current view controller in the cellForRowAtIndexPath
function - if the view controller is the data source of the table view, this would be just cell.viewController = self
. 您需要在cellForRowAtIndexPath
函数中分配当前的视图控制器-如果该视图控制器是表视图的数据源,则只能是cell.viewController = self
。
Then, in the textButton
function, you can present the message composer: 然后,在textButton
函数中,可以显示消息textButton
:
self.viewController.presentViewController(message, true, nil)
For the dismissal in didFinishWithResult
, just call 对于didFinishWithResult
的解雇,只需调用
self.viewController.dismissViewController(true, nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.