代码之家  ›  专栏  ›  技术社区  ›  Nicolas Miari

模式表上的NSProgressIndicator没有动画

  •  1
  • Nicolas Miari  · 技术社区  · 10 年前

    我的主窗口控制器有一个工具栏项,可以触发模式表的显示。该表应显示长时间异步进程的进度(例如,与服务器同步本地数据)。

    这是触发模式表的操作:

    var syncProgressWindowController: SyncProgressWindowController!
    
    // ...
    
    @IBAction func syncWithServer(_ sender: AnyObject) {
    
        // (Actual HTTP code not implemented)
    
        syncProgressWindowController = SyncProgressWindowController()
        syncProgressWindowController.loadWindow()
    
        guard let modalWindow = syncProgressWindowController.window else {
            return
        }
    
        self.window?.beginSheet(modalWindow, completionHandler: { (response) in
            // THIS GETS EXECUTED. 
            // However, the code below has no effect:   
    
            self.syncProgressWindowController.progressIndicator.startAnimation(self)
    
            // self.syncProgressWindowController.progressIndicator is 
            // NOT nil, despite windowDidLoad() not being called
            // (see below)
        })
    }
    

    模式表窗口控制器(类 SyncProgressWindowController 定义如下:

    @IBOutlet weak var progressIndicator: NSProgressIndicator!
    
    
    convenience init() {
        self.init(windowNibName: "SyncProgressWindow")
    }
    
    override func windowDidLoad() {
        super.windowDidLoad()
        // Breakpoints here don't work, logs don't print to the console.
        // Not called? But outlet _is_ set (see above).
    }
    

    xib文件(SyncProgressWindow.xib)具有:

    • 文件的所有者标识/类设置为“SyncProgressWindowController”
    • 窗口具有文件所有者的新引用出口 window
    • 窗口具有 delegate
    • 窗口未选中“Visible at Launch”(启动时可见)(因此以模式显示没有问题)。
    • 进度已将新的引用插座连接到文件所有者的 progressIndicator .

    1. SyncProgressWindow控制器 windowDidLoad() 做 不 get call(执行不会在断点处停止,并且不会打印日志)。
    2. 尽管如此,酒店/门店 进度指示器 是以某种方式设置的,因为当我尝试设置动画时,应用程序不会崩溃,代码如下:
      self.syncProgressWindowController.progressIndicator.startAnimation(self)

    我错过了什么?

    1 回复  |  直到 10 年前
        1
  •  1
  •   avvensis    10 年前

    当您关闭工作表时,completionHandler将被触发 endSheet(_:returnCode:)

    我不擅长xib文件,但当我用禁用行时 loadWindow ,已调用windowDidLoad。我不确定这是不是正确的方式。

    推荐文章