为什么我的数组没有被填充?

时间:2016-02-26 23:21:44

标签: ios objective-c arrays twitter

好吧,我有点不在我的联盟中但是这里......我正在努力为客户提供一些iPhone应用程序的更新(自2013年以来它还没有更新......只是为了放进入上下文编程的年龄)。在对应用程序进行简单更新的同时,我注意到twitter feed部分一直在崩溃。我检查了调试并发现了这个错误。

[_NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array

我知道数组是空的......我只是不确定为什么。这是我认为填充数组的代码

- (void)loadData {
NSURL *tutorialsUrl = [NSURL URLWithString:@"https://twitter.com/EdwinOrange/lists/kentucky-general-assembly"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];

TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];

NSString *tutorialsXpathQueryString = @"//p[@class='TweetTextSize js-tweet-text tweet-text']";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];

NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {

    NSString *strResponse = @"";

    for (int l=0; l<[[element children] count]; l++)
    {

            strResponse =[strResponse stringByAppendingString:[[[element children] objectAtIndex:l]  content]];

        NSArray *_children = [[[element children] objectAtIndex:l]  children];

        NSLog(@"count = %d",[_children count]);

        for (int k=0; k<[_children count]; k++)
        {
            NSLog(@"%@",[[_children objectAtIndex:k] children]);
            NSArray *_internalChildren = [[_children objectAtIndex:k] children];

            for (int j=0; j<[_internalChildren count]; j++)
            {
                NSLog(@"%@",[[_internalChildren objectAtIndex:j] content]);
                strResponse = [strResponse stringByAppendingFormat:@"%@",[[_internalChildren objectAtIndex:j] content]];
            }

        }

    }

    Tutorial *tutorial = [[Tutorial alloc] init];
    [newTutorials addObject:tutorial];

    tutorial.title = strResponse;

   NSLog(@"strResponse = %@",strResponse);

    NSLog(@"Data---%@",tutorial.title);

}
_data = newTutorials;

delegateObj.arrDetailContent = [_data mutableCopy];


}

我们还值得注意,Log不会返回上述代码的任何信息。我添加了一个异常断点,该断点在此行处断开(因为_data数组为空)

 Tutorial *data = [_data objectAtIndex:indexPath.row];

这也可能有助于追踪问题(这是TwitterController.m的顶部)

#pragma mark - Calling Twitter feeds

-(void)getAndParseTwitterFeeds
{
[self loadAtData];
[self loadNames];
[self loadData];

[self loadImages];
[self loadHours];

[self loadLink];
[self loadImages];
[self loadHours];
}

-(void)getFeeds
{
 [self getAndParseTwitterFeeds];
}

-(void)getFeedsLocally
{
_link = delegateObj.arrTwitterLink;
_objects = delegateObj.arrObjects;
_members = delegateObj.arrMemberName;
_data = delegateObj.arrDetailContent;
arrProfileImages = delegateObj.arrImages;
_hours = delegateObj.arrHour;

[self updateTableViewWithTheData];
}

希望这是足够的解释......我真的希望有人可以帮我弄清楚为什么数组没有被填充。感谢!!!!

编辑:我现在开始怀疑HTML解析器是否在推文中遇到图像问题。此代码来自2013年左右,其中包含twitter的内嵌图像。这会导致数组返回空吗?

另外值得注意的是,数组_link,_members,_hours等都正确填充,并且在loadData的“NSString * strResponse”部分之前具有相同的编码。

0 个答案:

没有答案