开发者

iPhone SDK NSInternalInconsistencyException

开发者 https://www.devze.com 2023-01-21 00:14 出处:网络
I\'m hitting a wall over and over again, trying to solve a problem I\'ve got in xcode. I\'m a newbie and started coding just a while ago.

I'm hitting a wall over and over again, trying to solve a problem I've got in xcode. I'm a newbie and started coding just a while ago.

I'm trying to make a XML parser based on this tutorial: http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader

which works fine separately, but when I'm implementing it into my own project, I get the 'NSInternalInconsistencyException' error, as a result of the following code:

----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];
    }
}

I've tried to remove the if-phrase, and then it calls the correct function, but the data which is supposed to be overhanded, won't get through.

Project setup

The project is a tab-based application. I'm having three classes:

  • Parser
  • AlphaTab
  • RootDelegate

In RootDelegate I used the following code to initialize the tab-view, and then to initialiaze the AlphaTab as a tableView being part of a 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.

So good so far.. the problem comes when I use the Parser class, which parses a given XML file. This class is initialized and only implemented in the AlphaTab - therefore it has nothing to do with the RootDelegate class at all. The initialization is done as:

----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];
  }

}

I'm suspecting the parameter withDelegate's value "self" to be the problem, which I think referres to the super class RootDelegate, but I'm not sure. Likewise, I don't know to pass the AlphaTab class' delegate to the function, which I think would solve the problem.

I'm ought to think, that the problem could be created f开发者_StackOverflow中文版rom this line aswell:

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

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

I've done some research about protocols and respondsToSelector, but honestly, I didn't understand much, since my code is seen from the programmatic perspective of view, without using the InterfaceBuilder at all, since I've been adviced to do that. It hasn't lead to the solution of the problem either.

For further understanding, I then want this function in AlphaTab.m to be called, when the information is parsed.

----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];
     }

I've looked on the net, and I found some explications about the NSInternalInconsistencyException. I've tried to do them as well, for example by setting everybody with themselves as delegates. However, I had no luck. What wonders me most, is that when I use the Parser without having to subclass it's caller (this case: AlphaTab) to a main class, it works like a charm.

I hope you guys can give me a clue. If you need any more information please ask, and I'll be in disposition.

//Brinck10


Please see @warrenm and his comment.

0

精彩评论

暂无评论...
验证码 换一张
取 消