我一遍又一遍地敲墙,试图解决我在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
看起来你可能在选择器名称中有一个额外的冒号。 – warrenm 2010-10-21 18:08:23
谢谢!我发现:D! – 2011-01-09 20:03:42