UITableView中包含多个部分的总行数

Jul*_*les 3 cocoa-touch objective-c uitableview

我需要计算我的总行数UITableView,但是我有多个部分.我可以访问表格视图上的属性吗?如果没有,我该如何找到这些信息?

jac*_*ash 6

UITableView从xCode的新文件对话框中创建一个"Objective-c Category",并将此方法添加到它:

-(NSInteger)numberOfRowsInTotal{
    NSInteger sections = self.numberOfSections;
    NSInteger cellCount = 0;
    for (NSInteger i = 0; i < sections; i++) {
        cellCount += [self numberOfRowsInSection:i];
    }

    return cellCount;
}
Run Code Online (Sandbox Code Playgroud)

然后将您的类别标题导入到您需要访问此方法的任何类中,您可以找到所需的内容.