gpt4 book ai didi

ios - 如何在 Swift 中从模态弹出窗口调用 Controller ?

转载 作者:行者123 更新时间:2023-11-30 14:12:05 29 4
gpt4 key购买 nike

我有三个 Controller ,我需要这个导航:

|第一届VC | -> |弹出窗口VC | -> |第二次VC |

第一个使用弹出框显示模态视图,然后使用协议(protocol)从模态视图中显示第二个 Controller 。

协议(protocol)调用该方法,然后,它应该调用第二个 Controller ,但事实并非如此!我尝试执行 segue 并调用 Controller ,但没有任何反应,事实上,它重新加载第一个 Controller 而不是调用第二个 Controller 。请帮忙。我认为我在委托(delegate)方面一定有错误,但我不知道是什么。(英语很差,我知道)

一件重要的事情是,firstViewcontroller 是从 tabbarcontoller 中的另一个 Controller 调用的。

提前致谢。

这是代码:

PopoOverController:

import UIKit
protocol basketDelegate {
func didSelectValue()
}
class PopoverViewController: UITableViewController {
var delegate: basketDelegate!
let options = ["Filters", "Basket"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
let rdc = storyboard!.instantiateViewControllerWithIdentifier("FirstViewController") as! FirstViewController
self.delegate = rdc
}

// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return options.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
cell.textLabel?.textAlignment = .Center
cell.textLabel?.textColor = colorWithHexString("#1C7393")
cell.textLabel?.text = options[indexPath.row]
return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
delegate?.didSelectValue()
}
}

第一个 Controller

import UIKit

class FirstViewController: AEAccordionTableViewController,
UIPopoverPresentationControllerDelegate, UISearchBarDelegate,basketDelegate {

override func viewDidLoad() {
super.viewDidLoad()

var Filters = PopoverViewController()
Filters.delegate = self

}

// MARK: - Popup filter call
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "popoverSegue" {
let popoverViewController = segue.destinationViewController as UIViewController
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
popoverViewController.popoverPresentationController!.delegate = self
}
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}


func didSelectValue() {

//Option 1--Failed!
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil);
let SecondViewControllerObject : UIViewController = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController;
self.presentViewController(SecondViewControllerObject, animated: true, completion: nil);

//Option 2--Failed
self.performSegueWithIdentifier("secondSegue", sender: self)

//Option 3--Failed
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let SecondViewControllerObject : UIViewController = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController;
let navigationController = UINavigationController(rootViewController: SecondViewControllerObject)
self.presentViewController(navigationController, animated: true, completion: nil)

//Option 4--Failed
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
FirstViewController()!.presentViewController(vc, animated: true, completion: nil)

//Option 5--Failed
self.navigationController?.presentViewController(vc, animated: false, completion: nil)

}
}

第二个 Controller

import UIKit

class SecondViewController: AEAccordionTableViewController {

@IBOutlet weak var dismissButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()

}
@IBAction func dismissTap(sender: UIButton) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}

最佳答案

您的第一个 View Controller 应该是 PopoverViewControllerDelegate,而不是basketDelegate。

关于ios - 如何在 Swift 中从模态弹出窗口调用 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31663922/

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