Obj-c Three20 库目录中缺少选择器

发布于 2024-08-20 20:44:43 字数 3406 浏览 3 评论 0原文

我在 iPhone 应用程序中使用 http://github.com/facebook/ Three20 。我已按照说明将该框架包含在我的项目中。我现在已经验证了两次(根据 google 群组和 IRC 上的人的建议)。当某些 Three20 代码尝试在 UIView 上使用编目选择器时,我收到以下错误:

-[TTSearchTextFieldancestorOrSelfWithClass:]: 无法识别的选择器发送到实例 0x3a85ee0'

当我触摸文本字段时,会触发此异常。

这对我来说是一个问题,如果我不为 TTSearchTextField 分配数据源,它不会触发错误。所以,从逻辑上讲,我认为它一定是我的数据源。

  1. 我在数据源中的每个函数上都放置了一个断点。
  2. 运行程序,正如预期的那样调用了 init 并调用了访问器代表。
  3. 点击文本字段,没有调用我的数据源,并且发生运行时异常。

我被这个难住了。我以前在使用带有目录的外部库时从未遇到过问题。我可以提供有关项目设置的更多信息,只需询问具体细节,因为那里有相当多的信息。

创建 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];

我正在使用的代码为我的数据源

#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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-08-27 20:44:43

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

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

I don't think it's your data source. -ancestorOrSelfWithClass: is a category method that extends UIView and is added in UIViewAdditions.h. The reason you're getting the error when adding your data source is probably that whatever code sends the -ancestorOrSelfWithClass: message probably isn't called if the data source is unassigned.

When compiling static libraries for inclusion into iPhone applications, under 2.x you needed to add -ObjC to your Other Linker Flags to make sure category methods were linked into the library. In 3.x, that doesn't seem to work properly, so -all_load needed to be added as well to the Other Linker Flags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文