iOS开发Swift-UITableView-func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int

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

返回一个整形.

作用:

UITableView的DataSource,用来确定cell的个数.numberOfRowsInSection就是在界面中的行数.

设置某一章节(section)中的单元格数量,必须实现

是一个 UITableViewDataSource 协议中的必需方法,用于返回给定部分中的行数。简单来说,这个方法告诉 UITableView 有多少行需要显示。

这个方法有两个参数:

  • tableView:UITableView 对象,这是你要提供数据的表格视图。
  • section:一个整数,表示你想知道行数的部分。

这个方法需要返回一个整数,表示在给定部分中的行数。

例如:

 如果你的应用程序的每个部分都有不同数量的行,那么你可能需要根据 section 参数返回不同的值。例如:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
    switch section {  
    case 0:  
        return 5  
    case 1:  
        return 3  
    default:  
        return 0  
    }  
}

 

posted @ 2023-09-18 15:02  临易  阅读(31)  评论(0编辑  收藏  举报