views:

38

answers:

1

Hi

If it is unclear what I mean from the headline, I am referring to the functionality that is in the Facebook app where to topmost cell in a "Feed" view is a "Load new posts" button that extends upwards "forever". You have to pull it down a bit for it to display it self.

Background In my case I reload the data for the entire UITableView (plain style) as the user type in a search field (which means fairly often), I then let the user filter the results using a slider. This functionality makes it so that there are more than one version of my data source, an array and a filteredArray.

If I were to implement the functionality the "quick" way I would set my:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.productListFiltered count] +1;
}

To return the count plus one, this would give me an extra cell. Then I would have to go through cellForRowAtIndexPath, DidSelectRowAtIndexPath etc. etc. all the delegate methods for the tableView and do exceptions for when indexPath.row == 0. It would have to riddle the controller with so many exceptions that it would be unreadable.

I could also try to change my model array, so each time It was set the data source for my tableVIew I would make the NSArray into an NSMutableArray and stuff an "empty" object in the first place.

This would also give some strange code as I would just have to move all the exception code to my CustomTableCellView (a custom view I add to the cell's subview). I populate the TableVIew often and from different places depending on whether the data is filtered or not.

Would it maybe be a better approach to attach a subview to the top of the tableView it self? but how would I go about giving the user the possibility to pull it on screen?

I am having a hard time finding a sound way through this, some way that does not fight the "best practice" for the UITableView.

Hope someone can offer a bit of guidance. Thank you.

+1  A: 

You should just use table sections. The search field and controls go in one section and the data in the second. When you return cells you just need to check the section and then access the data for that section instead of the other.

TechZen
Hi TechZenTook some reading up on before I got it, but the section solution only adds self-explanatory code to the delegate methods:) and everything works fine.Thank You very much.
RickiG