Last active
March 22, 2020 08:21
-
-
Save lukeredpath/305676 to your computer and use it in GitHub Desktop.
A decorator around UILocalizedIndexedCollation that automatically adds the search icon. Updated to support ARC.
This file contains hidden or 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
// | |
// LJSearchableIndexCollation.h | |
// | |
// | |
// Created by Luke Redpath on 16/02/2010. | |
// Copyright 2010 LJR Software Limited. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
/* | |
A simple decorator around UILocalizedIndexedCollation that inserts the | |
{{search}} magnifying glass icon into the section index titles and adjusts | |
the section index as necessary to account for the extra index item. | |
Use as a direct replacement for UILocalizedIndexedCollation in indexed | |
table views that have a search interface. | |
*/ | |
@interface FRIndexedCollationWithSearch : NSObject { | |
UILocalizedIndexedCollation *collation; | |
} | |
@property(nonatomic, readonly) NSArray *sectionTitles; | |
@property(nonatomic, readonly) NSArray *sectionIndexTitles; | |
+ (id)currentCollation; | |
- (id)initWithCollation:(UILocalizedIndexedCollation *)_collation; | |
- (NSInteger)sectionForObject:(id)object collationStringSelector:(SEL)selector; | |
- (NSInteger)sectionForSectionIndexTitleAtIndex:(NSInteger)indexTitleIndex; | |
- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector; | |
@end |
This file contains hidden or 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
// | |
// LJSearchableIndexCollation.m | |
// | |
// | |
// Created by Luke Redpath on 16/02/2010. | |
// Copyright 2010 LJR Software Limited. All rights reserved. | |
// | |
#import "FRIndexedCollationWithSearch.h" | |
@implementation FRIndexedCollationWithSearch | |
@dynamic sectionTitles; | |
@dynamic sectionIndexTitles; | |
+ (id)currentCollation; | |
{ | |
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation]; | |
return [[[self alloc] initWithCollation:collation] autorelease]; | |
} | |
- (id)initWithCollation:(UILocalizedIndexedCollation *)_collation; | |
{ | |
if (self = [super init]) { | |
collation = [_collation retain]; | |
} | |
return self; | |
} | |
- (void)dealloc; | |
{ | |
[collation release]; | |
[super dealloc]; | |
} | |
#pragma mark - | |
- (NSInteger)sectionForObject:(id)object collationStringSelector:(SEL)selector | |
{ | |
return [collation sectionForObject:object collationStringSelector:selector]; | |
} | |
- (NSInteger)sectionForSectionIndexTitleAtIndex:(NSInteger)indexTitleIndex | |
{ | |
if(indexTitleIndex == 0) { | |
return NSNotFound; | |
} | |
return [collation sectionForSectionIndexTitleAtIndex:indexTitleIndex-1]; | |
} | |
- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector | |
{ | |
return [collation sortedArrayFromArray:array collationStringSelector:selector]; | |
} | |
#pragma mark - | |
#pragma mark Accessors | |
- (NSArray *)sectionTitles; | |
{ | |
return [collation sectionTitles]; | |
} | |
- (NSArray *)sectionIndexTitles; | |
{ | |
return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray:[collation sectionIndexTitles]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment