views:

22

answers:

2

I am trying to use the count of objects from my FRC fetch so that I can create an "Add" cell after all of my fetched objects have been listed in a UITableView. Is there a method for returning the number of objects fetched? I can only find a method that returns the count of sections for a given FRC.

+1  A: 

The easiest way to do this is by setting the tableFooterView property of your table view. The footer view will be displayed below the last table view cell.

Bjarne Mogstad
+1 Sometime the answer to "how to I do that," is "don't do that."
TechZen
Can the tableFooterView behave as a cell with UITableViewCellEditingStyleInsert? If so, do you know how I would initialize it as such?
Spindler
Bjarne, that makes good sense. I'm trying to read up on how to do that, but I'm not finding any material on setting a custom cell as the TableFooterView. I'm trying to play around with it in code myself, but it appears that the editingStyle property of the UITableViewCell I create is readonly. I try to set it with footerCell.editingStyle = UITableViewCellEditingStyleInsert; ...but receive an error. If I can get that set properly, I assume I would then set my custom cell (I'm calling it "footerCell") as the tableView.tableFooterView like so --> self.tableView.tableFooterView = footerCell.
Spindler
+1  A: 

Simplistically, you You want a count of fetchedObjects. So:

[[myFRC fetchedObjects] count];

The problem that you're going to have with adding an additional cell, is that every time the table ask for the count of sections and rows, you're going to have add 1 to the count so the table knows to add the extra row.

Bjarne Mogstad is correct. It's quicker and cleaner to put the add element in a header or footer for the table itself. That way, the table directly and cleanly represents the data structure without having to constantly adjust for the phantom row.

TechZen
Conceptually, I think I understand how the table's footer works, but I want to make sure I'm thinking straight. In code, I need to create a tableViewCell with my desired text and editing style, and then set it as the tableView.tableFooterView...is that correct?
Spindler
The footer and headers are just standard views, not table view cells. You can set them up however you wish.
TechZen