0

Hi
I'd like to pass an NSInteger to a tableView controller and then use it to set a badge.
In this case, the NSInteger I'd like to pass is the number of rows in a tableView, returned with Core Data (numberOfRows).

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger numberOfRows = 0;

    if ([[fetchedResultsController sections] count] > 0) {
        id NSFetchedResultsSectionInfo sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
        numberOfRows = [sectionInfo numberOfObjects];
    }

    return numberOfRows;
}

How can I declare another NSInteger and then pass it to a tableView controller?

Thanks,
Matthew

matteodv
  • 3,992
  • 5
  • 39
  • 73
  • Not sure if I understood your question correctly but wouldn't you just use the code above? – Rog Nov 30 '10 at 21:52
  • Sorry for the delay... This code above is that I use in my principal controller, managing core data. I'd like to pass the numberOfRows number to another tableView controller to set a method... I tried with NSUserDefaults and works but the number isn't updated every time the number of rows in table view changes... Can you help me? – matteodv Dec 01 '10 at 13:31

1 Answers1

1

It sounds like you may need two fetched results controllers in the second table view controller. The first FRC would manage the table itself and the second would calculate the existing number of rows in the first table's data.

You would have to assign the second tableview controller as the delegate for both FRC and then in the delegate methods test which controller fired a change and take the appropriate action.

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • Can you describe me how can I do this? How can I assign this delegate? – matteodv Dec 01 '10 at 21:25
  • The delegate is usually just the tableview controller. You would just assign the controller to the FRC's delegate property. See the NSFetchedResultsControllerDelegate protocol for details. – TechZen Dec 03 '10 at 17:45
  • Thanks for your comment... I must read this protocol but before of this, I created a singleton class to pass this number. It works but if I change the number of rows, deleting or adding new rows, this number isn't updated... How can I update this number with a singleton class? This is my code: http://pastie.org/1345205 – matteodv Dec 03 '10 at 18:48