作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 iPad 应用程序的 SplitView,其中包含主视图(左)和详细 View (右)。我希望,当我单击主视图中的按钮时,此调用父分割 View 上的委托(delegate)方法并将新 View 推到顶部,但永远不会调用委托(delegate)方法。为什么?
代码如下:
主视图:
protocol newAlbumDelegate{
func openAlbum()
}
class newAlbumController: UIViewController {
var delegate:newAlbumDelegate?
@IBAction func buttonClick(sender:UIButton){
delegate?.openAlbum()
}
}
SplitView:
import UIKit
class AlbumSplitController: UISplitViewController, newAlbunDelegate {
var newAlbumToAdd:newAlbumController = newAlbumController()
//Delegate
func openAlbum(){
print("Do something")
}
override func viewDidLoad(){
super.viewDidLoad()
self.newAlbumToAdd.delegate = self
}
有什么帮助吗?
问候,
最佳答案
在masterViewController
中,将splitViewController
指定为委托(delegate):
protocol newAlbumDelegate{
func openAlbum()
}
class newAlbumController: UIViewController {
var delegate:newAlbumDelegate?
@IBAction func buttonClick(sender:UIButton){
delegate?.openAlbum()
}
override func viewDidLoad(){
super.viewDidLoad()
let splitView = self.splitViewController as! AlbumSplitController
self.delegate = splitView
}
}
你的splitViewController
变成:
class AlbumSplitController: UISplitViewController, newAlbumDelegate {
//Delegate
func openAlbum(){
print("Do something")
}
}
关于ios - 委托(delegate)不适用于 SplitView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39101306/
我是一名优秀的程序员,十分优秀!