我有一个带有主应用(左)和详细(右)视图的SplitView,适用于iPad应用。我想要的是,当我单击主视图中的一个按钮时,在父拆分视图上调用委托方法并推送一个新视图,但是从不调用委托方法。为什么呢?
这里是代码:
主视图:
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
}
任何帮助?
此致
答案 0 :(得分:0)
在masterViewController
内,将splitViewController
指定为代理人:
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")
}
}