gpt4 book ai didi

ios - 委托(delegate)不适用于 SplitView

转载 作者:行者123 更新时间:2023-11-30 13:08:02 26 4
gpt4 key购买 nike

我有一个 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/

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