為什麼“文件所有者”有時會有“視圖”出口?我可以添加我自己的嗎? (Why does "File's Owner" sometimes have a "view" outlet? Can I add my own?)


問題描述

為什麼“文件所有者”有時會有“視圖”出口?我可以添加我自己的嗎? (Why does "File's Owner" sometimes have a "view" outlet? Can I add my own?)

當我創建一個類型為 NSViewController 的新“Cocoa 類”並選中“同時為用戶界面創建 XIB 文件”時,我得到一個空白的 XIB 文件。它的“文件所有者”有一個連接到自定義視圖的出口“視圖”。

當我創建一個新的“視圖”(xib 文件)時,它的“文件所有者”沒有“查看”插座或任何其他類型。有一個“新引用出口”,我無法將它連接到視圖。

為什麼一種xib在這裡有一個“視圖”,而另一種沒有?有沒有辦法在我自己的 xib 上向“文件所有者”添加“視圖”出口?

“也為用戶界面創建 XIB 文件”創建的 xib 一定有一些特別之處


參考解法

方法 1:

I made xibs both ways, and diff'd them. For a xib created through that checkbox, its "File's Owner" has a Custom Class which is the name of an NSViewController. That's what gives it the "view" outlet.

You can set the Class of the File's Owner on any xib to an NSViewController, and then it will get a "view" outlet for you to set.

(by NahaNaha)

參考文件

  1. Why does "File's Owner" sometimes have a "view" outlet? Can I add my own? (CC BY‑SA 2.5/3.0/4.0)

#iboutlet #nsviewcontroller #interface-builder #XCode #xib






相關問題

iOS - IB 視圖模式 (iOS - IB view mode)

NSWindow 的 IBOutlet 組件什麼時候初始化? (When IBOutlet components of NSWindow are initialized?)

收到內存警告和內存洩漏 (Receive memory warning and memory leak)

如何在 init 方法中從 NIB 加載 IBOutlets? (How to load the IBOutlets from NIB in the the init method?)

將 xib 從一個項目複製到另一個項目 (copy the xib from one project to another project)

將案例編碼到 appDelegate 文件中 (The case(s) coding into appDelegate file)

nib 中的 UIView 在 iPad 上是 nil,在 iPhone 上不是 nil (UIView in nib is nil on iPad, and not nil on iPhone)

awakeFromNib 無法從 UILabel 獲取值,也無法禁用 UIButton (awakeFromNib can't get value from UILabel and can't disable UIButton)

“找不到名為 ViewController 的類的任何信息” ("Could not find any information for class named ViewController")

在 Xcode 7 中將出口從文件連接到情節提要 (Connect outlet from file to storyboard in Xcode 7)

為什麼“文件所有者”有時會有“視圖”出口?我可以添加我自己的嗎? (Why does "File's Owner" sometimes have a "view" outlet? Can I add my own?)

Interface Builder 中的 IBOutletCollection 集排序 (IBOutletCollection set ordering in Interface Builder)







留言討論