小编Man*_*ena的帖子

Objective-C中的方法名称是相同的.

我的ViewController对象必须实现所需的表视图方法,以便它可以充当数据源.从UITableView.h:

@required  
-(NSInteger)tableView:(UITableView *)tableView
                       numberOfRowsInSection:(NSInteger)section;
-(UITableViewCell *)tableView:(UITableView *)tableView
                       cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)

这有点令人困惑.

第一个参数是什么(UITableView*)tableView,为什么它与方法名称相同?它看起来像是一个指向TableView对象的指针.为什么给它命名与方法相同?

其次,我理解虽然这看起来像重载,但实际上有两种方法,tableview:numberOfRowsInSectiontableView:cellForRowAtIndexPath.为什么是这样?

以下链接很有帮助.这里将提供任何其他帮助,特别是关于命名约定.

Objective-C中的方法重载?
Objective C中的函数重载是否可行?
如何在Objective-C中传递多个参数?

parameters methods objective-c naming-conventions uitableview

3
推荐指数
1
解决办法
493
查看次数