Ios 我在UITableViewController中覆盖了什么?

Ios 我在UITableViewController中覆盖了什么?,ios,uitableview,swift,Ios,Uitableview,Swift,许多关于UITableView的教程要求我们在MyUITableViewController:UITableViewController中重写此函数: override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int { return 10 } 我知道这是UITableView中numberOfRowsInSection方法的实现,但我不理解语言机制 tableV

许多关于UITableView的教程要求我们在
MyUITableViewController:UITableViewController
中重写此函数:

override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
    return 10
}
我知道这是
UITableView
中numberOfRowsInSection方法的实现,但我不理解语言机制


tableView
UITableViewController
的继承属性,而不是方法。那么重写究竟是如何工作的呢?

同一方法的objective-C语法是

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section; 
它给出了
tableView:numberOfRowsInSection:

当你习惯于使用Objective-C时,你会在心理上忽略
表格视图:
部分,而专注于
行数部分

当Objective-C方法名称转换为swift时,第一个参数将成为方法名称,因此您将获得
tableView(tableView:UITableView?,numberOfRowsInSection:Int)->Int


对您的问题的简短回答是,您正在使用该签名覆盖函数,而不是
tableView
属性
UITableViewController
符合
UITableViewDataSource
协议:

tableView
是在
UITableViewDataSource


UITableViewController
有一个协议函数的默认实现,
MyUITableViewController
可以
override

这只是swift帮助符合Objective-C详细函数名的愚蠢方式。我相信tableView实际上是一个函数,它有几个不同的参数集,这些参数反过来定义了几个不同的函数。您只是用一组特定的参数覆盖函数。@TravisM。这是正确的。在ObjC中,方法名相当于函数名和所有命名参数的串联。但是
tableView
不是方法。在
UITableViewController
内部,您可以看到
var tableView:UITableView