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


問題描述

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

自從我開始使用 Xcode (4.6.3) 以來,這個錯誤一直讓我發瘋。每當我嘗試將 Storyboard 項目鏈接到我的代碼時,都會收到錯誤消息:

找不到名為 ViewController 的類的任何信息。

自定義類也會發生這種情況。我嘗試過以下方法:

  • 刪除委託數據。
  • 刪除和重新添加類。
  • 重新啟動 Xcode。
  • 重新安裝 Xcode。

無論類是什麼,我都無法通過 ctrl‑drag 在我的任何項目中創建連接。全新的模板應用程序也會出現同樣的問題。如果我手動輸入代碼然後按 ctrl‑drag,我可以建立一個有效的連接,但我不能 t 自動添加。到目前為止,我在 Internet 上找不到任何幫助。有什麼指點嗎?


參考解法

方法 1:

What solved this issue for me was actually deleting the class from the project.

Steps:

  1. In the project file explorer (left panel) find the class and right click ‑> Delete
  2. Remove reference (do not move to trash as you will lose the class for good)
  3. Right click on the folder that contained the class ‑> Add files to ...
  4. Find the class you just deleted in the file system

This seems to force Xcode to link the class back into the storyboard.

Note: for me the following did not work:

  • Closing Xcode
  • Cleaning the project
  • Deleting the class name from the storyboard and re‑entering it

I think this is a bug on Apple's part

方法 2:

In case anyone is still frustrated by this, there's a trick to get things working.

What I do is manually enter an outlet into my class, for example: @IBOutlet weak var someView: UIView!, and drag from the code to the view in IB or storyboard. After this, I am able to drag from IB / Storyboard to my class to make connections, assistant editors recognizes the class in "Automatic", etc...

Works every time.

方法 3:

For me removing them from your target membership in the right column and adding them again did the trick enter image description here

方法 4:

Sometime Xcode does due to VC not referencing class file. The simple solution for this is:

write property manually as given.

class YourClassName{

     @IBOutlet weak var YourTableName: UITableView!

}

This will make a empty link sign before @IBOutlet, open your project in assistant editor then click link sign enter image description here and drag into the View which you want to connect (i have connected with TableView). and thats it. Enjoy Happy Coding!!!

方法 5:

I tried everything and it didn't work, so for me what worked is:

  • Clean Build folder and project.
  • Open Projects (Window ‑> Projects)
  • Find your project on the list and delete the Derived Data
  • Close Xcode
  • Restart computer (without choosing to reopen windows that are open)
  • run Xcode
  • Work!

All my view controllers were not being recognized, so deleting all files and re‑adding was not an option as this is a big project.

(by user2597451Chris HarrisonAndrew RobinsonRuud VisserMRizwan33gmogames)

參考文件

  1. "Could not find any information for class named ViewController" (CC BY‑SA 2.5/3.0/4.0)

#iboutlet #iOS #XCode






相關問題

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)







留言討論