代码之家  ›  专栏  ›  技术社区  ›  Idan

Iphone-NumberOfSectionsTableView的默认实现

  •  1
  • Idan  · 技术社区  · 14 年前

    我正在创建UITableViewController的一个新子类,并使用下面的默认值 实施。 它不会编译,因为显然没有所谓的“节数”变量, 这是怎么回事?

    #pragma mark -
    #pragma mark Table view data source
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return number of sections;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
        return <#number of rows in section#>;
    }
    
    2 回复  |  直到 11 年前
        1
  •  2
  •   Alex Reynolds    14 年前

    琴弦 number of sections <#number of rows in section#> 必须是实际整数,与数据源中的节数和行数相对应。

    例如,如果您有一个由五个对象组成的数组,您想用表视图来表示这些对象,并且希望它们都进入一个部分,那么您需要返回 1 -numberOfSectionsInTableView: 5 -tableView:numberOfRowsInSection: .

    你可能想看看苹果的 Table View Programming Guide for iOS

        2
  •  0
  •   Frade    11 年前

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    

    默认返回值为1。 Check it in documentation

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section