Created
September 22, 2009 21:02
-
-
Save dima767/191445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
// Return 1 section which will be used to display the giant blank UITableViewCell as defined | |
// in the tableView:cellForRowAtIndexPath: method below | |
if ([self.searchResults count] == 0){ | |
return 1; | |
} else if ([self.searchResults count] < self.webServiceDataModel.total) { | |
// Add an object to the end of the array for the "Load more..." table cell. | |
return [self.searchResults count] + 1; | |
} | |
// Return the number of rows as there are in the searchResults array. | |
return [self.searchResults count]; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
// Special cases: | |
// 1: if search results count == 0, display giant blank UITableViewCell, and disable user interaction. | |
// 2: if last cell, display the "Load More" search results UITableViewCell. | |
if ([self.searchResults count] == 0){ // Special Case 1 | |
// Disable user interaction for this cell. | |
UITableViewCell *cell = [[[UITableViewCell alloc] init] autorelease]; | |
cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
return cell; | |
} else if (indexPath.row == [self.searchResults count]){ // Special Case 2 | |
LoadMoreSearchResultsTableViewCell *cell = (LoadMoreSearchResultsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"LoadMoreResultsCell"]; | |
if (cell == nil) { | |
[[NSBundle mainBundle] loadNibNamed:@"LoadMoreSearchResultsTableCell" owner:self options:nil]; | |
cell = self.loadMoreSearchResultsCell; | |
self.loadMoreSearchResultsCell.loadMoreLabel.text = @"Load More Results..."; | |
self.loadMoreSearchResultsCell.loadMoreLabel2.text = @""; | |
} | |
// Return a standard cell | |
self.loadMoreSearchResultsCell.loadMoreLabel.text = @"Load More Results..."; | |
self.loadMoreSearchResultsCell.loadMoreLabel2.text = @""; | |
return cell; | |
} | |
static NSString *CellIdentifier = @"SearchResultsCell"; | |
SearchResultsTableViewCell *cell = (SearchResultsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
[[NSBundle mainBundle] loadNibNamed:@"SearchResultsTableCell" owner:self options:nil]; | |
cell = self.searchResultsCell; | |
} | |
} | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
if ([self.searchResults count] == 0){ | |
return; | |
// Special Case for the "Load More Results..." button for paging. | |
} else if (indexPath.row == [self.searchResults count]) { | |
// Register for the notification | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(employeeDataReceived:) | |
name:@"WebServiceCallCompleted" object:nil]; | |
// Unhide the spinner, and start animating it. | |
[self.loadMoreSearchResultsCell.loadMoreIndicator startAnimating]; | |
self.loadMoreSearchResultsCell.loadMoreLabel.text = @""; | |
self.loadMoreSearchResultsCell.loadMoreLabel2.text = @"Loading..."; | |
// Start the connection... | |
[self.webServiceDataModel getNextSearchResultsPage]; | |
// Disable user interaction if/when the loading/search results view appears. | |
[self.tableView setUserInteractionEnabled:NO]; | |
// Unhighlight the load more button after it has been tapped. | |
NSIndexPath* selection = [self.tableView indexPathForSelectedRow]; | |
if (selection) | |
[self.tableView deselectRowAtIndexPath:selection animated:YES]; | |
} else { | |
// Slide in the a details view. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment