Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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 Swift错误:类型为'的值;NSObject->;()';AnimalListTableViewController';没有成员';tableView';_Ios_Xcode_Swift - Fatal编程技术网

Ios Swift错误:类型为'的值;NSObject->;()';AnimalListTableViewController';没有成员';tableView';

Ios Swift错误:类型为'的值;NSObject->;()';AnimalListTableViewController';没有成员';tableView';,ios,xcode,swift,Ios,Xcode,Swift,我正试图消除swift xcode中的这些错误 如果截图太小,下面是代码 import UIKit class AnimalListTableViewController: UITableViewController { override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 4 } let indexP

我正试图消除swift xcode中的这些错误

如果截图太小,下面是代码

import UIKit

class AnimalListTableViewController: UITableViewController
{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    let indexPath = self.tableView.indexPathForSelectedRow()//this is where the error appears, it says  Value of type 'NSObject -> () -> AnimalListTableViewController' has no member 'tableView'
    override func prepareForSegue(segue: UIStoryboardSegue,
        sender: AnyObject?)
    {
            if let DetailViewController =
                segue.destinationViewController
                    as? DetailViewController {
            }
    }

    if let indexPath = self.tableView.indexPathForSelectedRow()
    {
        DetailViewController.Animal = animals[indexPath.row]
    }
}
代码格式不正确

在生成错误的行中,您正在
animalisttableviewcontroller
声明的上下文中工作,而不是在函数中。从左到右读取时,就好像您试图声明
animalisttableviewcontroller
类的常量数据成员
indepath

看起来您正在尝试这样做:

class AnimalListTableViewController: UITableViewController
{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }

    override func prepareForSegue(segue: UIStoryboardSegue,
        sender: AnyObject?)
    {
        if let detailViewController = segue.destinationViewController as? DetailViewController, let indexPath = self.tableView.indexPathForSelectedRow {
            detailViewController.Animal = animals[indexPath.row]
        }
    }
}
还清理了其他一些东西:

  • 不要将类名(
    DetailViewController
    )也用作变量名。将其更改为
    detailViewController
  • if let
    语句折叠为单个语句。清洁工避免选择