1

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.

  1. I placed a break point on every function in my data source.
  2. Ran the program, as expected the init was called and the accessor delegates was called.
  3. 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
4

1 回答 1

2

我不认为这是您的数据源。 -ancestorOrSelfWithClass:是扩展 UIView 并添加在UIViewAdditions.h. -ancestorOrSelfWithClass:添加数据源时出现错误的原因可能是,如果未分配数据源,则可能不会调用发送消息的任何代码。

在编译静态库以包含在 iPhone 应用程序中时,在 2.x 下,您需要添加-ObjC到您的 Other Linker Flags 以确保将类别方法链接到库中。在 3.x 中,这似乎无法正常工作,因此 -all_load也需要添加到其他链接器标志中。

于 2010-02-08T23:53:52.723 回答