Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ViewController不确认协议UITableViewDataSource_Ios_Uitableview_Swift - Fatal编程技术网

Ios ViewController不确认协议UITableViewDataSource

Ios ViewController不确认协议UITableViewDataSource,ios,uitableview,swift,Ios,Uitableview,Swift,我做得很好,但仍然显示错误“ViewController不符合协议” 我在这个网站上搜索了很多,我发现了同样的问题,但并没有找到任何正确的答案 我已经将UITableView连接添加到UITableViewDelegate和UITableViewDataSource,但仍然显示错误我应该怎么做 这是我的密码 class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { override fu

我做得很好,但仍然显示错误“ViewController不符合协议” 我在这个网站上搜索了很多,我发现了同样的问题,但并没有找到任何正确的答案 我已经将UITableView连接添加到UITableViewDelegate和UITableViewDataSource,但仍然显示错误我应该怎么做

这是我的密码

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBOutlet var tableView: UITableView!


func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int
{
    return 20
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{

    let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
    cell.textLabel.text="row#\(indexPath.row)"
    cell.detailTextLabel.text="subtitle#\(indexPath.row)"

    return cell

}



}

请注意删除了

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBOutlet var tableView: UITableView!


func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
    return 20
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
    cell.textLabel.text="row#\(indexPath.row)"
    cell.detailTextLabel.text="subtitle#\(indexPath.row)"

    return cell

}



}

cellForRowAtIndexPath方法上的代码存在其他错误

UITableViewCell.textLabel和UITableViewCell.detailTextLabel返回可选的UILabel,因此您需要首先将它们展开(表示在选项之后添加!)。因此,改变这两行如下,你是好的

cell.textLabel!.text="row#\(indexPath.row)"
cell.detailTextLabel!.text="subtitle#\(indexPath.row)"
此外,CellForRowatineXpath的方法签名是错误的。拆下!在最后一个UITableViewCell上。应该是这样的:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

好的,我从代码中删除了这两行,但仍然显示相同的错误。你确定你捕获了这四行吗?当我编译代码时,我发布了错误消息更改。