简体   繁体   English

添加到NSMutableArray时,TouchXML CXMLNode.m无法识别的选择器

[英]TouchXML CXMLNode.m unrecognized selector when adding to NSMutableArray

I'm new to Objective C and XML, so this is going to look pretty rough. 我是Objective C和XML的新手,所以这看起来很粗糙。

My code is as follows: 我的代码如下:

#import "dbCommunicator.h"
#import "BookInfo.h"
#import "TouchXML.h"

@implementation dbCommunicator

-(void)getNextBooks {
    if(self.bookListing == nil) {
        for(int i = 0; i < 5; i++) {
            BookInfo *newBook = [[BookInfo alloc] init];
            [self.bookListing addObject:newBook];
        }
        self.currentPage = 0;
    }
    if(self.currentPage == 10) {
        self.currentPage = 0;
    }

    NSString *test = @"<Authors><Book.Author><Id>1026</Id><Name>Mark Twain</Name></Book.Author></Authors>";
    NSString *bookQueryString = [NSString stringWithFormat:@"http://bookworm.azurewebsites.net/api/book/list/5/%d",_currentPage];
    NSURL *bookQueryURL = [NSURL URLWithString: bookQueryString];
    self.currentPage++;
    NSError *theError = NULL;
    NSDictionary *mappings = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"http://schemas.datacontract.org/2004/07/Bookworm.Models.ResponseModels",
                              @"datacontract",
                              nil];
    CXMLDocument *xmlReturn = [[CXMLDocument alloc] initWithXMLString:test options:0 error:&theError];
    NSArray *returnedBooks = [xmlReturn nodesForXPath:@"//Authors" error:&theError];
    for(CXMLElement *resultElement in returnedBooks) {
        NSLog(@"%s", "We actually got here");
    }
}

There's a lot of junk code in there at the moment. 目前,这里有很多垃圾代码。 The intention is to pull an XML file from a database and put its information into an array of BookInfo classes. 目的是从数据库中提取XML文件,并将其信息放入BookInfo类的数组中。 For the moment, I simplified by just using a test XMLstring to ensure it wasn't an issue with what the database was sending me. 目前,我通过仅使用测试XMLstring来确保它不是数据库发送给我的问题来简化了操作。 This makes the dictionary (to deal with the namespace issues TouchXML has) superfluous. 这使得字典(用于处理TouchXML拥有的名称空间问题)变得多余。 Anyways. 无论如何。

It always crashes with a unrecognized selector error on this line: 它总是在此行崩溃,并出现无法识别的选择器错误:

[theArray addObject:[CXMLNode nodeWithLibXMLNode:theNode freeOnDealloc:NO]];

In this context: 在这种情况下:

if (xmlXPathNodeSetIsEmpty(theXPathObject->nodesetval))
    theResult = [NSArray array]; // TODO better to return NULL?
else {
    NSMutableArray *theArray = [NSMutableArray array];
    int N;
    for (N = 0; N < theXPathObject->nodesetval->nodeNr; N++) {
        xmlNodePtr theNode = theXPathObject->nodesetval->nodeTab[N];
        [theArray addObject:[CXMLNode nodeWithLibXMLNode:theNode freeOnDealloc:NO]];
    }
}

and with that, I'm totally at a loss. 因此,我完全不知所措。 I've tried plenty of things, scoured every StackOverflow post even closely related and tried their fixes, nothing's working. 我已经尝试了很多事情,甚至仔细检查了每一个StackOverflow帖子,并且尝试了修复方法,但没有任何效果。 Any suggestions? 有什么建议么?

array is a static method on NSArray a super class of NSMutableArray that returns an NSArray object. array是NSArray上的静态方法,它是NSMutableArray的超类,它返回NSArray对象。 NSArray does not respond to the method addObject: NSArray不响应方法addObject:

Try instead NSMutableArray *theArray = [NSMutableArray new]; 尝试改用NSMutableArray *theArray = [NSMutableArray new];

The problem probably is on this selector: 问题可能出在此选择器上:

nodeWithLibXMLNode:freeOnDealloc:

if you try to see your crash log in the console, should be written the selector unrecognized and should be this. 如果您尝试在控制台中查看崩溃日志,则应将选择器写为无法识别的选择器,并且应该是这样。 If so check the class reference of the CXMLNode . 如果是这样,请检查CXMLNode的类引用。

I checked now, and that method doesn't exists . 我现在检查了,那个方法不存在 Just a method might be useful for you in some way, that is: 只是一种方法可能以某种方式对您有用,即:

- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;

Enjoy ;) 请享用 ;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将对象添加到NSMutableArray时无法识别的选择器 - Unrecognized selector when adding an object to NSMutableArray iOS无法识别的选择器发送到实例 - 将NSDictionary添加到NSMutableArray - iOS unrecognized selector sent to instance - adding NSDictionary to NSMutableArray 尝试将字典添加到nsMutableArray时获取“无法识别的选择器” - Get 'unrecognized selector' when trying to add dictionary to nsMutableArray NSMutableArray遇到__NSArrayI removeObjectAtIndex:]问题:无法识别的选择器 - NSMutableArray running into problems with __NSArrayI removeObjectAtIndex:]: unrecognized selector 无法识别的选择器发送到实例NSArray / NSMutableArray - unrecognized selector sent to instance NSArray/NSMutableArray 将UITableView添加到UIPageViewController时,“无法识别的选择器已发送到实例” - 'unrecognized selector sent to instance' when adding UITableView to UIPageViewController 将MKCircleOverlay添加到MKMapView时,无法识别的选择器[MKCircle pointCount] - Unrecognized selector [MKCircle pointCount] when adding MKCircleOverlay to MKMapView 将观察者添加到PDFView时,无法识别的选择器发送到实例 - Unrecognized selector sent to instance when adding observer to PDFView 将UITableView添加为SubView时,无法识别的选择器发送到实例 - Unrecognized selector sent to instance when adding a UITableView as SubView 滑动时无法识别的选择器 - Unrecognized selector when swipe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM