benhowdle89
benhowdle89

Reputation: 37504

UITableView in iPhone app - how to get number of rows

How can i store the number of current rows in a uitable into a variable?

This is my code for the table (that i think might be relevant):

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];

}

Upvotes: 5

Views: 24864

Answers (3)

Alejandro Rangel
Alejandro Rangel

Reputation: 1670

I want to display a uiAlert if the number of rows goes above 1. But i dont know how to

That's easy, just check if your value in this case is above 0:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  id <NSFetchedResultsSectionInfo> sectionInfo =
      [[self.fetchedResultsController sections] objectAtIndex:section];
  if([sectionInfor numberOfObjects]>0){
      <<Put your code here>>
  }
      return [sectionInfo numberOfObjects]];
}

Upvotes: 0

aahrens
aahrens

Reputation: 5590

Typically you'll have a data source that's backing the UITableView, usually array. In that case you could simply do [myDataSourceArr count].

Upvotes: 2

John Parker
John Parker

Reputation: 54445

You should really get this from the source of the data, rather than the table view itself, I'd have thought. (It's a bit arse about face as they'd say around here.)

That said, you could use the numberOfRowsInSection: method within the UITableView as you've shown in your example.

Upvotes: 14

Related Questions