我在iPhone應用程序中使用http://github.com/facebook/three20。我按照說明將框架包含在我的項目中。我已經驗證了兩次(在谷歌組和IRC上的人們的建議)。我得到當一些Three20代碼試圖在UIView的使用編目選擇以下錯誤:從Obj-c Three20庫目錄中缺少選擇器
- [TTSearchTextField ancestorOrSelfWithClass:]:無法識別的選擇發送到實例0x3a85ee0'
當我觸碰此異常被觸發文本字段。
下面是我的踢球者,如果我不給TTSearchTextField指定數據源,它不會觸發錯誤。所以,邏輯上我認爲它一定是我的數據源。
- 我在我的數據源中的每個函數放置了一個斷點。
- 運行該程序,如預期的那樣調用了init並調用了訪問者代表。
- 點擊文本字段,沒有調用我的dataSource併發生運行時異常。
我很難過這個。我以前從未遇到過使用外部庫的問題。我可以提供有關項目設置的更多信息,只是詢問具體情況,因爲那裏有相當多的信息。我使用的是創建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
確實。這正是IRC和郵件列表中的人們所建議的。這是一個3.x項目,我在其他鏈接器標誌中同時具有-ObjC和-all_load。還有其他建議嗎?我想知道是否有辦法確認它實際上在編譯時應用這些標誌... – jsapara 2010-02-09 03:08:24
我調試了此項目的構建過程,發現它並未在鏈接上使用-all_load。該項目明確地定義了它,但它沒有被應用到我們的任何構建目標中。我進去並將-all_load添加到目標,現在它可以工作。 我回到之前使用Three20的項目,鏈接器標誌在項目中明確定義。我創建了一個新項目並投入了一個快速的Three20 UI小部件,並將鏈接器標誌添加到項目中(而不是目標)。工作得很好,所以在Xcode文件中一定有些奇怪/損壞。無論哪種方式,它都解決了。 – jsapara 2010-02-09 04:51:56