Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-08-2011, 01:46 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
bella is on a distinguished road
Question UISearchdisplay controller, tableView, core data - question, thanks

Hi,

I have integrated the search function to my app to query core data/.sqlite and it works ok. But I have a problem and I am not sure which class configuration should I look at, could someone points me to the light, thanks

Basically my model is this

TableView 1
Display Product Category
selectRow --> TableView2

TableView 2
Display Products of selected Category
selectRow --> TableView3

As I integrated the UISearchBar in TableView 1, I wish to have the function when people search the product they want and it will show up the product's name right away in the table view. I tried, but the result is showing the Category which contains the "searched product".

So, how could I get this to show up correctly and which section of configuration should I look at? Is it the configure cell part? And also, since TableView 1 is a sectioned table view, how could I get that to display correctly when performing search

Table View section
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
	if (self.searchIsActive) {
        return [self.filteredListContent count];
    } else {
		return [[fetchedResultsController sections] count];
	}
}
Now is obviously wrong...


Configure cell, hopefully can display Category when search not active and display Products when search is active
Code:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
	NSManagedObject *entity = nil;
	if (self.searchIsActive){
                // Configure the cell to show the searched item's name
		entity = [[self filteredListContent] objectAtIndex:[indexPath row]];
		cell.textLabel.textColor = [UIColor blackColor];
		} else {
		// Configure the cell to show the category's name
		cell.textLabel.textColor = [UIColor blackColor];
		entity = [fetchedResultsController objectAtIndexPath:indexPath];
	}
	cell.textLabel.text = [entity valueForKey:@"nameEN"];
}
The search predicate
Code:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
		NSPredicate * predicate = [NSPredicate predicateWithFormat:@"ANY products.nameEN CONTAINS[cd] %@, searchText];
		self.filteredListContent = [[[self fetchedResultsController] fetchedObjects] filteredArrayUsingPredicate:predicate];
}
The core database structure is

Category
nameEN
products --- one to many relations --> Product

Product
nameEN
spec
category --- many to one relation -- > Category

THANK YOU

Last edited by bella; 03-08-2011 at 01:50 AM.
bella is offline   Reply With Quote
Old 03-09-2011, 06:13 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
bella is on a distinguished road
Default

would be great if anyone could help, thanks
bella is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, iphone, uisearchdisplaycontroller, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
17 members and 344 guests
Absentia, akphyo, apatsufas, BinHex, dre, fredidf, Gaz, gmarro, host number one, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0