I'm using http://github.com/facebook/three20 in my iPhone application. I've followed the instructions to include the framework in my project. I've verified it twice now (at the recommendations of people on the google group and IRC). I get the following error when some of the Three20 code attempts to use a Cataloged selector on the UIView:
-[TTSearchTextField ancestorOrSelfWithClass:]: unrecognized selector sent to instance 0x3a85ee0'
This exception is triggered when I touch the text field.
Here's the kicker for me, if I don't assign a datasource to the TTSearchTextField it doesn't trigger the the error. So, logically I figured it must be my dataSource.
- I placed a break point on every function in my data source.
- Ran the program, as expected the init was called and the accessor delegates was called.
- Tapped the text field, no calls to my dataSource and the run-time exception occurs.
I'm stumped on this one. I've never had issues using external libs with Catalogs in them before. I can provide more information on the project setup, just ask for specifics since there's quite a bit of information there.
Code I'm using the create the TTSearchTextField:
// setup Country
self.searchFieldCountry = [[TTSearchTextField alloc]initWithFrame:CGRectMake(156, 145, 146, 37)];
self.searchFieldCountry.borderStyle = UITextBorderStyleRoundedRect;
self.searchFieldCountry.placeholder = @"Country";
self.searchFieldCountry.autocapitalizationType = UITextAutocapitalizationTypeNone;
OLLocationSearchDataSource *ds = [[OLLocationSearchDataSource alloc]init];
self.searchFieldCountry.dataSource = ds;
[self.view addSubview:self.searchFieldCountry];
[ds release];
Code for my DataSource:
#import "OLLocation.h"
#import "AppSession.h"
@implementation OLLocation
@synthesize locationData = _locationData;
@synthesize locationMode,country,region;
- (NSMutableArray*)delegates {
if (!_delegates) {
_delegates = TTCreateNonRetainingArray();
}
return _delegates;
}
- (BOOL)isLoadingMore {
return NO;
}
- (BOOL)isOutdated {
return NO;
}
- (BOOL)isLoaded {
return !!_AllLocationData;
}
- (BOOL)isLoading {
return NO;
}
- (BOOL)isEmpty {
return !_AllLocationData.count;
}
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
}
- (void)invalidate:(BOOL)erase {
}
- (void)cancel {
// cancel a search if possible
}
- (void)loadNames {
_AllLocationData = [[AppSession getAppSession] getCountries];
}
- (void)search:(NSString*)text {
[self cancel];
self.locationData = [NSMutableArray array];
if (text.length) {
text = [text lowercaseString];
for (NSString* name in _AllLocationData) {
if ([[name lowercaseString] rangeOfString:text].location == 0) {
[_locationData addObject:name];
}
}
}
}
- (void)dealloc {
[super dealloc];
}
@end
@implementation OLLocationSearchDataSource
@synthesize locations = _locations;
-(id)init {
if (self = [super init]) {
_locations = [[OLLocation alloc] init];
_locations.locationMode = OLLocationModeCountry;
self.model = _locations;
}
return self;
}
-(void)dealloc {
TT_RELEASE_SAFELY(_locations);
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTTableViewDataSource
- (void)tableViewDidLoadModel:(UITableView*)tableView {
self.items = [NSMutableArray array];
for (NSString* name in _locations.locationData) {
TTTableItem* item = [TTTableTextItem itemWithText:name URL:@"http://google.com"];
[_items addObject:item];
}
}
- (void)search:(NSString*)text {
[_locations search:text];
}
- (NSString*)titleForLoading:(BOOL)reloading {
return @"Searching...";
}
- (NSString*)titleForNoData {
return @"No names found";
}
@end