- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题 1)
我花了几个小时试图解决这个问题,从我读到的内容来看,这些是实现 UITableView 所需的两个函数,但它仍然给我标题中的错误:
import UIKit
class UITableView: UIViewController, UITableViewDataSource,UITableViewDelegate
{
override func viewDidLoad()
{
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
}
}
问题 2)
TableView 是我为我的应用程序实现的选项卡式 View Controller 的一部分。我希望我的 TableView Controller 具有一旦按下就会打开另一个 ViewController 的条目。我怎样才能实现这样的事情?
提前谢谢
最佳答案
您的 ViewController 设置不正确。要么创建一个只是 UITableView 的 UITableViewController,要么将 UITableView 添加到 UIViewController(就像您几乎完成的那样)。
didSelectRowAt 方法将允许您转到新的 viewController,但在我的示例中仅当它在 Storyboard 中正确设置时。
UITableViewController选项
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
performSegue(withIdentifier: "SegueIdentifier", sender: self)
}
UIViewController 选项
(在此示例中,需要通过 Storyboard 添加 UITableView)
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
// MARK: - Table view delegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
performSegue(withIdentifier: "SegueIdentifier", sender: self)
}
关于ios - UITableView 不符合协议(protocol) UITableViewDataSource 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41998240/
我已经检查了其他几个问题,答案似乎在数据源方法的声明中。但是,我找不到我的方法声明有什么问题。 这是我的类(class): import UIKit class GuestControl: UITab
到目前为止,我很喜欢 MonoTouch,但是一旦您通过了几个初学者类(class),就会发现缺少文档和示例。 我正在努力解决在 MonoTouch 中填充简单 UITableView 的简单概念。我
在我们的应用程序中,我们有几个 UITableView,它们具有网络支持的数据源,实际填充这些数据源可能需要一些时间。以下是通常发生的情况: 用户触发 View 。 在 viewDidLoad 中,创
我有一个 UITableView,它应该呈现分成部分 的条目。数据需要一些时间来处理,因此它是这样完成的: @interface AsyncTable() NSMutableArray* _alp
数据源方法没有被触发我的 tableView 仍然是空的。使用断点,我可以看到数据源从未执行过我不明白为什么以及如何 import UIKit class SearchResultsViewContr
class EmployeeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var emp
我有一个 NSArray 从服务器获取的歌曲。那是我的原始数据源。该数组包含以 NSDictionary 和 NSArray 作为后端的自定义对象。 我想知道使用 NSDictionary 实现格式化
尝试将我的表的值分配给 self 时出现以下错误。 Cannot assign a value of type 'ActivityViewController' to a value of type
如何在 Swift 中定义协议(protocol):( @protocol Protocol - (Class)generateObject; @end 编辑:如果我想在 OC 中定义一个函数,如下
我在我的一个 UITableViews 中遇到索引越界异常,我认为可能是一些多线程问题。这是我认为正在发生的事情: 我有一个 UITableView,它的数据源是一个普通的 NSMutableArra
我在连接到 TodayViewController 的 ViewController 中使用 UITableView。我想使用我的 Parse 数据库中的数据加载到 TableView 中。 这是我的
我从 Xcode 模板创建了一个新的主从应用程序 我发现主界面(在本例中为 BirdMasterViewController)继承自 UITableViewController,和 UITableVi
我写代码有困难,协议(protocol)出错,我用的是xcode 7.3.1 //2 Method dari protokol UITableViewDataSource->method 1. fun
目前,我在我的应用程序中设置了以下内容: 例如,我有一个游戏列表,其中的游戏有不同的状态,我希望某个状态位于某个部分等。 因为我有 3 种不同的状态,所以我将使用 NSDictionary,其中 St
由于 UITableView 在 UIViewController 中,我创建了一个符合 UITableViewDataSource 协议(protocol)的类,并将其附加到 UIViewContr
我的项目中有 4 个文件: myTableViewController.swift myTableViewDataSource.swift myCustomCell.swift 我的自定义单元格.xi
我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际的 Xcode 7 中执行它。除了 UITableViewDataSource 问题外,我下面的代码看起来是正确的。
问题:如何通过扩展编写 UITableViewDataSource 的默认实现? Swift支持协议(protocol)扩展中的默认实现,UITableViewDataSource是一个协议(prot
我设置了 tableview 数据源,但它无法识别他的错误类型“ViewController”不符合协议(protocol)“UITableViewDataSource” import UIKit c
因此,我在 Xcode 中收到“Type ViewController does not conform to protocol UITableViewDataSource”错误。我已经实现了所需的功
我是一名优秀的程序员,十分优秀!