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 02-07-2012, 06:57 PM   #1 (permalink)
Beginner iOS Dev
 
Join Date: Feb 2011
Location: Boston
Posts: 372
cityofangels is on a distinguished road
Default How to make a custom UISearchController datasource?

I have a universal iOS app. The iPhone version has a search view that has a UISearchDisplayController. The iPad app has a custom UI that essentially does the same thing.

I want to make a class that handles all the searching stuff that I can use for both the iPad and iPhone. Can anyone give me any guidance as to how to get started? Do I need to subclass NSObject that handles this stuff? I think its just as simple as adding the methods there then calling them from the two view controllers?

I have the iPhone version working so all I need to do is abstract the search code to this new class.

Last edited by cityofangels; 02-07-2012 at 07:12 PM.
cityofangels is offline   Reply With Quote
Old 02-07-2012, 07:16 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Couldn't you just use the same view controller 'UISearchDisplayController' in the iPad view? There may be some small modifications to handle the iPad view but you should be able to use the same controller.

Quote:
Originally Posted by cityofangels View Post
I have a universal iOS app. The iPhone version has a search view that has a UISearchDisplayController. The iPad app has a custom UI that essentially does the same thing.

I want to make a class that handles all the searching stuff that I can use for both the iPad and iPhone. Can anyone give me any guidance as to how to get started? Do I need to subclass NSObject that handles this stuff? I think its just as simple as adding the methods there then calling them from the two view controllers?

I have the iPhone version working so all I need to do is abstract the search code to this new class.
GHuebner is offline   Reply With Quote
Old 02-07-2012, 07:22 PM   #3 (permalink)
Beginner iOS Dev
 
Join Date: Feb 2011
Location: Boston
Posts: 372
cityofangels is on a distinguished road
Default

Quote:
Originally Posted by GHuebner View Post
Couldn't you just use the same view controller 'UISearchDisplayController' in the iPad view? There may be some small modifications to handle the iPad view but you should be able to use the same controller.
The iPad has a completely custom UI actually. It looks like the spotlight on the iPhone.

Right now, I have this all in one class. I should be able to abstract the second method into its own class so I can call it from both the iPhone and iPad view controllers.

Code:
- (void)searchBarSearchButtonClicked:(UISearchBar *)iSearchBar {
    [self performSearchForString:iSearchBar.text];
}


- (void)performSearchForString:(NSString *)iSearchString {
    self.hideTable = NO;
    self.isSearching = YES;
    [self.searchDisplayController.searchResultsTableView reloadData];
    
    NSArray *aFilteredArray = [self.currentScopeArray filteredArrayUsingPredicate:self.searchScopePredicate];
    self.masterArray = [NSMutableArray arrayWithObjects:[NSNull null], [NSNull null], [NSNull null], [NSNull null], nil];
    for (NSInteger x = 0; x < aFilteredArray.count; x++) {
        NSMutableDictionary *aPostBody = [NSMutableDictionary dictionaryWithCapacity:3];
        NSDictionary *aScopeDictionary = [aFilteredArray objectAtIndex:x];
        NSString *aSearchType = [aScopeDictionary objectForKey:@"searchType"];
        [aPostBody setObject:iSearchString forKey:@"searchTerm"];
        [aPostBody setObject:aSearchType forKey:@"searchType"];
        
        ISTServiceRequest *aFormRequest = [ISTServiceRequest post:[[CMAConfiguration sharedConfiguration] endpointForKey:@"search"] body:aPostBody requestDidFinishBlock:^(ISTServiceRequestReceipt *aReceipt) {
            if (aReceipt.responseObject && [aReceipt.responseObject isKindOfClass:[NSArray class]]) {
                NSArray *aResultsArray = aReceipt.responseObject;
                Class aSearchObjectType = nil;
                if ([aSearchType isEqualToString:@"GUEST"] || [aSearchType isEqualToString:@"MEMBER"]) {
                    aSearchObjectType = [CMACustomer class];
                }  else if ([aSearchType isEqualToString:@"RESERVATION"] || [aSearchType isEqualToString:@"PICKUP"]) {
                    aSearchObjectType = [CMAReservation class];
                }
                [self.masterArray replaceObjectAtIndex:aReceipt.tag withObject:[aSearchObjectType objectsFromServerDictionaries:aResultsArray]];
                [self stopAnimationAtSection:aReceipt.tag];
            }
        }];
        aFormRequest.tag = x;
    }
}
cityofangels is offline   Reply With Quote
Old 02-07-2012, 07:34 PM   #4 (permalink)
Beginner iOS Dev
 
Join Date: Feb 2011
Location: Boston
Posts: 372
cityofangels is on a distinguished road
Default

Actually I may have gotten some of it done.

My iPhone VC now just has this:

Code:
- (void)performSearchForString:(NSString *)iSearchString {
    self.hideTable = NO;
    self.isSearching = YES;
    [self.searchDisplayController.searchResultsTableView reloadData];
    
    NSArray *aFilteredArray = [self.currentScopeArray filteredArrayUsingPredicate:self.searchScopePredicate];
    self.masterArray = [NSMutableArray arrayWithObjects:[NSNull null], [NSNull null], [NSNull null], [NSNull null], nil];
    CMASearchController *searchController = [[CMASearchController alloc]init];
    [searchController performSearchWithArray:aFilteredArray andSearchTerm:iSearchString];
    [searchController release];
}
and my search class has this:

Code:
- (void)performSearchWithArray:(NSArray *)iArray andSearchTerm:(NSString *)iSearchTerm {
    for (NSInteger x = 0; x < iArray.count; x++) {
        NSMutableDictionary *aPostBody = [NSMutableDictionary dictionaryWithCapacity:3];
        NSDictionary *aScopeDictionary = [iArray objectAtIndex:x];
        NSString *aSearchType = [aScopeDictionary objectForKey:@"searchType"];
        [aPostBody setObject:iSearchTerm forKey:@"searchTerm"];
        [aPostBody setObject:aSearchType forKey:@"searchType"];
        
        ISTServiceRequest *aFormRequest = [ISTServiceRequest post:[[CMAConfiguration sharedConfiguration] endpointForKey:@"search"] body:aPostBody requestDidFinishBlock:^(ISTServiceRequestReceipt *aReceipt) {
            if (aReceipt.responseObject && [aReceipt.responseObject isKindOfClass:[NSArray class]]) {
                NSArray *aResultsArray = aReceipt.responseObject;
                Class aSearchObjectType = nil;
                if ([aSearchType isEqualToString:@"GUEST"] || [aSearchType isEqualToString:@"MEMBER"]) {
                    aSearchObjectType = [CMACustomer class];
                }  else if ([aSearchType isEqualToString:@"RESERVATION"] || [aSearchType isEqualToString:@"PICKUP"]) {
                    aSearchObjectType = [CMAReservation class];
                }
                [self.masterArray replaceObjectAtIndex:aReceipt.tag withObject:[aSearchObjectType objectsFromServerDictionaries:aResultsArray]];
                [self stopAnimationAtSection:aReceipt.tag];
            }
        }];
        aFormRequest.tag = x;
    }
}
But how can I handle these two lines from the search class that modify attributes in the iPhone vc?

Code:
                [self.masterArray replaceObjectAtIndex:aReceipt.tag withObject:[aSearchObjectType objectsFromServerDictionaries:aResultsArray]];
                [self stopAnimationAtSection:aReceipt.tag];
cityofangels is offline   Reply With Quote
Reply

Bookmarks

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: 397
14 members and 383 guests
7twenty7, chiataytuday, cristofercolmbos, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, raymng, ryantcb, stanny, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

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