【发布时间】:2015-12-17 12:15:16
【问题描述】:
我正在使用一个带有按钮的自定义单元格类。
import UIKit
protocol TouchDelegateForShotsCell {
func touchedTwitterButton()
}
class ShotsCell : UITableViewCell {
let touchDelegateForShotsCell: TouchDelegateForShotsCell = MasterViewController()
@IBAction func twitterButtonPressed(sender: AnyObject) {
touchDelegateForShotsCell.touchedTwitterButton()
}
}
当按下按钮时,我在 MasterViewController 中调用一个委托函数,其中包含以下用于在 Twitter 上共享的标准代码:
func touchedTwitterButton() {
var shareToTwitter :SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
self.presentViewController(shareToTwitter, animated: true, completion: nil)
}
我收到错误:
“尝试呈现其视图不在窗口层次结构中的 ViewController!”。
我尝试了几种解决方法。例如,创建一个单独的视图控制器并从按钮执行 segue。这部分有效,但是,当我尝试传递数据时,我得到另一个错误:
"'NSInvalidArgumentException',原因:接收方 ViewController 没有标识符为 'segueToTwitterShare' 的 segue"。
这不是真的。为此,我尝试删除我的应用程序并重新启动对某些人有用的 xcode。但是,问题仍然存在。
【问题讨论】:
标签: ios iphone swift uitableview delegates