iPhone SDK N内部一致性异常
我一次又一次地碰壁,试图解决我在xcode中遇到的一个问题。我是个新手,刚开始编写代码 我试图根据本教程制作一个XML解析器: 这两种方法单独运行很好,但当我将其实现到自己的项目中时,会出现“NSInternalInconsistencyException”错误,原因是以下代码:iPhone SDK N内部一致性异常,iphone,protocols,nsxmlparser,Iphone,Protocols,Nsxmlparser,我一次又一次地碰壁,试图解决我在xcode中遇到的一个问题。我是个新手,刚开始编写代码 我试图根据本教程制作一个XML解析器: 这两种方法单独运行很好,但当我将其实现到自己的项目中时,会出现“NSInternalInconsistencyException”错误,原因是以下代码: ----File: Parser.m---- - (void)parserDidEndDocument:(NSXMLParser *)parser { if ([_delegate respondsToSelect
----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短语,然后它调用正确的函数,但是应该被忽略的数据无法通过
项目设置
该项目是一个基于选项卡的应用程序。我有三节课:
分析器
字母表
根代理
在RootDelegate中,我使用以下代码初始化选项卡视图,然后将AlphaTab初始化为作为navigationView一部分的tableView:
----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.
到目前为止还不错。。当我使用Parser类时,问题就出现了,它解析给定的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的值self是问题所在,我认为这与超级类RootDelegate有关,但我不确定。类似地,我不知道如何将AlphaTab类的委托传递给函数,我认为这样可以解决问题
我应该认为,这一行也会产生问题:
----FILE: Parser.h ----
@protocol AlphaTab <UITableViewDelegate>
- (void)parsedInformation:(NSArray *)i;
@end
我在网上查了一下,发现了一些关于NSInternalInconsistencyException的解释。我也尝试过这样做,比如让每个人都把自己当作代表。然而,我没有运气。最让我惊奇的是,当我使用解析器而不必将其调用方子类化时,这种情况下:AlphaTab是一个主类,它就像一个符咒
我希望你们能给我一个线索。如果你需要更多的信息,请询问,我会处理的
//Brinck10请查看@warrenm和他的评论。看起来您的选择器名称中可能有一个额外的冒号。
----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];
}