gpt4 book ai didi

ios - 从未调用过通过 loadNibNamed() 从 xib 加载按钮

转载 作者:行者123 更新时间:2023-11-30 13:05:24 25 4
gpt4 key购买 nike

又一个问题出现了。我有一个覆盖我的孔屏的 View 。其中有一个用于显示 youTube 视频的 webView 和一个用于关闭的按钮。该 View 是通过 loadNibNamed() 加载的,无论我在做什么,我的 IBAction 都不会通过按下该按钮来调用。我尝试通过 Storyboard 创建 IBAction,也通过 addTarget 到按钮输出。两人都没有打过电话。当我单击我的按钮时,它可以到达,它显示默认的触摸动画。还在 viewDidLoad() 中打印按钮导出说 <UIButton: 0x17d25430; frame = (15 8; 39 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x17d25ae0>>所以它不是零。

我的布局如下所示。

  • 主屏幕:UIViewController、UITableViewDelegate、UITableViewDataSource、UIWebViewDelegate{}

    • 在主屏幕 tableView 之一中,有一个名为 videoViewCell 的自定义单元,其实现方式为:

    let cell = NSBundle.mainBundle().loadNibNamed("VideoViewCell",owner: self, options: nil)!.first as! VideoViewCell

videoViewCell:UITableViewCell,UITableViewDelegate,UITableViewDataSource {}具有:

weak var delegate: ActivityDetailVideoCellDelegate?

...

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
delegate?.selectedCellAtIndex(indexPath.row)
}

...

protocol ActivityDetailVideoCellDelegate: class {
func selectedCellAtIndex(index: Int)
}

我的 mainScreen 类有:

extension MainScreen: ActivityDetailVideoCellDelegate {
func selectedCellAtIndex(index: Int) {

let youtubeLink: String = "http://www.youtube.com/embed/\(selectedVideo)"
let youtubePopup = YouTubePopUpController()

youtubePopup.view.frame = self.view.bounds
youtubePopup.view.alpha = 0
youtubePopup.view.transform = CGAffineTransformMakeScale(1.3, 1.3)

let code: String = "<iframe width=\(youtubePopup.webView.bounds.width) height=\(youtubePopup.webView.bounds.height) src=\(youtubeLink) frameborder=0 allowfullscreen></iframe> <style>body { margin: 0; padding: 0; }</style>"

youtubePopup.webView.loadHTMLString(code, baseURL: nil)

self.view.addSubview(youtubePopup.view)

UIView.animateWithDuration(0.25, animations: { () -> Void in
youtubePopup.view.alpha = 1
youtubePopup.view.transform = CGAffineTransformMakeScale(1, 1)
})
}

}

YouTubePopUpController:UIViewController:

@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var closeButton: UIButton!


override func viewDidLoad() {
super.viewDidLoad()

print(closeButton)

closeButton.addTarget(self, action: #selector(self.closeButtonClicked(_:)), forControlEvents: .TouchUpInside)
}

@IBAction func closeButtonClicked(sender: AnyObject) {
print("close clicked")

UIView.animateWithDuration(0.25, animations: { () -> Void in
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3)
self.view.alpha = 0
}) { (finished) -> Void in
self.view.removeFromSuperview()
}
}

我的xib: xib

最佳答案

最终通过在 MainScreenViewController 中编写 @IBAction func closeButtonClicked(sender: AnyObject) {} 并在 func selectedCellAtIndex(index: Int) {} 中添加 Target 解决了我的问题> 在 closeButtonClicked 中调用我的 youtubePopUp 我将其设为全局:

@IBAction func closeButtonClicked(sender: AnyObject) {
print("close clicked")

youtubePopup!.webView.loadHTMLString("about:blank", baseURL: nil)
youtubePopup!.webView.mediaPlaybackRequiresUserAction = false

UIView.animateWithDuration(0.25, animations: { () -> Void in
self.youtubePopup!.view.transform = CGAffineTransformMakeScale(1.3, 1.3)
self.youtubePopup!.view.alpha = 0
}) { (finished) -> Void in
self.youtubePopup!.view.removeFromSuperview()
}

}

关于ios - 从未调用过通过 loadNibNamed() 从 xib 加载按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39438692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com