here's my code.. anyone can help?
// // SearchTableViewController.m // iFood // // Created by Admin on 6/8/10. // Copyright 2010 MyCompanyName. All rights reserved. //
import "SearchTableViewController.h"
import "iFoodAppDelegate.h"
import "Food.h"
import "FoodDetailViewController.h"
@implementation SearchTableViewController
@synthesize foods, filteredFoods, savedSearchTerm, savedScopeButtonIndex, searchWasActive;
pragma mark -
pragma mark Lifecycle methods
(void)viewDidLoad { self.title = @"Search";
// create a filtered list that will contain products for the search results table. self.filteredFoods = [NSMutableArray arrayWithCapacity:[self.foods count]];
// restore search settings if they were saved in didReceiveMemoryWarning. if (self.savedSearchTerm) { [self.searchDisplayController setActive:self.searchWasActive]; [self.searchDisplayController.searchBar setSelectedScopeButtonIndex:self.savedScopeButtonIndex];
[self.searchDisplayController.searchBar setText:savedSearchTerm]; self.savedSearchTerm = nil;
}
[self.tableView reloadData]; self.tableView.scrollEnabled = YES; }
(void)viewDidUnload { self.filteredFoods = nil; }
(void)viewDidDisappear:(BOOL)animated { // save the state of the search UI so that it can be restored if the view is re-created self.searchWasActive = [self.searchDisplayController isActive]; self.savedSearchTerm = [self.searchDisplayController.searchBar text]; self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}
(void)dealloc { [foods release]; [filteredFoods release];
[super dealloc]; }
pragma mark -
pragma mark UITableView data source and delegate methods
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { iFoodAppDelegate *appDelegate = (iFoodAppDelegate *)[[UIApplication sharedApplication] delegate];
/* If the requesting table view is the search display controller's table view, return the count of the filtered list, otherwise return the count of the main list. */ if (tableView == self.searchDisplayController.searchResultsTableView) { return [self.filteredFoods count]; } else { return appDelegate.foods.count; }
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; }
/* If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list. */ iFoodAppDelegate *appDelegate = (iFoodAppDelegate *)[[UIApplication sharedApplication] delegate]; Food *food = (Food *)[appDelegate.foods objectAtIndex:indexPath.row]; if (tableView == self.searchDisplayController.searchResultsTableView) { food = [self.filteredFoods objectAtIndex:indexPath.row]; } else { food = [appDelegate.foods objectAtIndex:indexPath.row]; }
cell.textLabel.text = food.FoodName; return cell; }
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { FoodDetailViewController *detailViewController = [[FoodDetailViewController alloc] init];
/* If the requesting table view is the search display controller's table view, configure the next view controller using the filtered content, otherwise use the main list. */ Food *food = nil; if (tableView == self.searchDisplayController.searchResultsTableView) { // product = [self.filteredListContent objectAtIndex:indexPath.row]; } else { food = [self.foods objectAtIndex:indexPath.row]; } detailViewController.title = food.FoodName;
[[self navigationController] pushViewController:detailViewController animated:YES]; [detailViewController release]; }
pragma mark -
pragma mark Table View Delegate Methods
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; }
@end