为什么 "Use of undeclared type UITableView" 发生在 Swift?
Why the "Use of undeclared type UITableView" happened in Swift?
我是 Swift
的新手。我创建了第二个 swift file
调用 DeviceInfo.swift
并在 Main.storyboard
.
中添加了一个 UIViewcontroller
我在UIViewcontroller(DeviceInfo)
里也加了一个UITableView
。
但是在我通过 command + left
将 UITableView
连接到 DeviceInfo.swift
后,出现错误 Use of undeclared type 'UITableView'
。错误显示如下。
问题
1.为什么 Use of undeclared type 'UITableView'
发生了?如何解决?
2。显示我将 dataSource
和 delegate
连接到 UIViewcontroller(DeviceInfo)
?
提前致谢。
您需要在文件顶部添加 import UIKit
,在您已经有 import Foundation
的区域。如果不导入 UIKit,您的对象将不知道 UITableView 是什么。
UITableView
在 UIKit 框架中,您没有导入它。所以import UIKit.
在你的viewDidLod
中:
self.tableView.dataSource = self;
self.tableView.delegate = self;
在您的 .h 文件中,您可以执行以下操作:
@interface YourClassName : UIViewController<UITableViewDataSource,UITableViewDelegate>
并确保将 tableView 与 IBOutlet
连接。
1.import UIKit
2.To 连接 delegate
和 dataSource
,
单击该点并拖动到您的 tableView。
我是 Swift
的新手。我创建了第二个 swift file
调用 DeviceInfo.swift
并在 Main.storyboard
.
UIViewcontroller
我在UIViewcontroller(DeviceInfo)
里也加了一个UITableView
。
但是在我通过 command + left
将 UITableView
连接到 DeviceInfo.swift
后,出现错误 Use of undeclared type 'UITableView'
。错误显示如下。
问题
1.为什么 Use of undeclared type 'UITableView'
发生了?如何解决?
2。显示我将 dataSource
和 delegate
连接到 UIViewcontroller(DeviceInfo)
?
提前致谢。
您需要在文件顶部添加 import UIKit
,在您已经有 import Foundation
的区域。如果不导入 UIKit,您的对象将不知道 UITableView 是什么。
UITableView
在 UIKit 框架中,您没有导入它。所以import UIKit.
在你的viewDidLod
中:
self.tableView.dataSource = self;
self.tableView.delegate = self;
在您的 .h 文件中,您可以执行以下操作:
@interface YourClassName : UIViewController<UITableViewDataSource,UITableViewDelegate>
并确保将 tableView 与 IBOutlet
连接。
1.import UIKit
2.To 连接 delegate
和 dataSource
,
单击该点并拖动到您的 tableView。