I need to calculate the total number of rows in my UITableView, however I have multiple sections. Is there a property on the table view I can access? If not, how can I find this information?
Create an "Objective-c Category" of UITableView from the new file dialogue of xCode and add this method to it:
-(NSInteger)numberOfRowsInTotal{
NSInteger sections = self.numberOfSections;
NSInteger cellCount = 0;
for (NSInteger i = 0; i < sections; i++) {
cellCount += [self numberOfRowsInSection:i];
}
return cellCount;
}
Then import your category header into any class that you need to access this method in et voila, you have what you're looking for.
You can easily calculate this value by iterating through each section.
NSUInteger allRows = 0;
for(NSInteger i = 0; i < [tableview numberOfSections]; i++)
{
allRows += [tableview numberOfRowsInSection:i];
}
If you would like a property you can easily add the above code to a category for UITableView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With