2010-10-21 73 views
0

我一遍又一遍地敲牆,試圖解決我在xcode中遇到的問題。我是新手,剛開始編碼。iPhone SDK NSInternalInconsistencyException

我試圖讓基於此教程的XML解析器:http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader

其單獨優秀作品,但是當我執行到我自己的項目,我得到「NSInternalInconsistencyException」錯誤,因爲下面的代碼的結果:

----File: Parser.m---- 

- (void)parserDidEndDocument:(NSXMLParser *)parser { 
if ([_delegate respondsToSelector:@selector(parsedInformation::)]){ 
    [_delegate parsedInformation:information]; 
}else{ 
     [NSException raise:NSInternalInconsistencyException 
    format:@"Delegate (%d) doesn't respond to parsedInformation:", _delegate]; 
    } 
} 

我試圖刪除if短語,然後調用相應功能,但應該被overhanded數據,不會得到通過。

項目設置

該項目是一個基於標籤的應用程序。我有三類:

  • 分析器
  • AlphaTab
  • RootDelegate

在RootDelegate我用下面的代碼來初始化製表視圖,然後到initialiaze的AlphaTab作爲的tableView一個navigationView被部分:

----RootDelegate.m ---- 

    tabBarController = [[UITabBarController alloc] init]; 
alphaTab = [[AlphaTab alloc] initWithTabTitle:@"AlphaTab" navigationTitle:@"Exploring"]; 

UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:alphaTab] autorelease]; 
    tableNavController.delegate = self; 
    [alphaTab release]; // creates your table view's navigation controller, then adds the created view controller. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory. 

那麼好爲止。當我使用帕爾斯問題就來了呃類,它解析給定的XML文件。這個類是初始化的,只能在AlphaTab中實現 - 因此它根本與RootDelegate類無關。初始化完成爲:

----File AlphaTab.m ---- 

- (void)loadData{ 
    if(information==nil){ 
    Parser *XMLParser = [[Parser alloc] init]; 
    [XMLParser parseFeed:@"http://frederikbrinck.com/bodil/Example.xml" withDelegate:self]; 
    [XMLParser release]; 
    }else { 
    [self.tableView reloadData]; 
    } 

} 

我懷疑參數withDelegate的價值「自我」是這個問題,我認爲referres給超類RootDelegate,但我不知道。同樣,我不知道要將AlphaTab類的委託傳遞給我認爲可以解決問題的函數。

我應該想,這個問題可以從該行藏漢創建:

----FILE: Parser.h ---- 

@protocol AlphaTab <UITableViewDelegate> 
- (void)parsedInformation:(NSArray *)i; 
@end 

我做了一些研究有關的協議和respondsToSelector,但說實話,我不明白了,因爲我的代碼是從編程的角度來看的,根本沒有使用InterfaceBuilder,因爲我已經被建議去做。它也沒有導致問題的解決。

爲了進一步理解,我在AlphaTab.m中調用這個函數,當信息被解析時。

----FILE AlphaTab.m ---- 

- (void)parsedInformation:(NSArray *)i { 
    NSLog(@"The parser has completed parsing"); 
    information = i; 
    NSLog(@"This is the information: %d", [[information objectAtIndex:0] objectForKey:@"tabTitle"]); 
    [self.tableView reloadData]; 
    } 

我在網上看過,並且發現了關於NSInternalInconsistencyException的一些說明。我也試圖做到這一點,例如將每個人都設爲代表。但是,我沒有運氣。最讓我感到奇怪的是,當我使用Parser而不必將其調用者(這種情況:AlphaTab)子類化爲主類時,它就像一個魅力。

我希望你們能給我一點線索。如果您需要更多信息,請詢問,我會處理。

// Brinck10

+0

看起來你可能在選擇器名稱中有一個額外的冒號。 – warrenm 2010-10-21 18:08:23

+0

謝謝!我發現:D! – 2011-01-09 20:03:42

回答

0

請參閱@warrenm和他的評論。