我想在运行时在数组中添加数据

时间:2014-05-15 09:39:03

标签: ios

这是我的代码:

NSData *result = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.raywenderlich.com/tutorials"]];
TFHpple *xpath = [[TFHpple alloc] initWithHTMLData:result]; //use xpath to search element
data = [xpath searchWithXPathQuery:@"//div[@class='content-wrapper']/ul/li/a"];
title = [[NSMutableArray alloc]init];

for (TFHppleElement *item in data)
{   //write log
    NSLog(@"Title : %@", item.content);
    NSLog(@"URL : %@", [item.attributes valueForKey:@"href"]);
    NSLog(@"-------------------------------");

    [title addObject:item.content];
//  [title addObject:getdata(item.content)];

}

1 个答案:

答案 0 :(得分:0)

if(data!= nil)     {         for(TFHppleElement *数据项)         {//写日志             if(item!= nil)             {                 NSLog(@"标题:%@",item.content);

            NSLog(@"URL : %@", [item.attributes valueForKey:@"href"]);

            NSLog(@"-------------------------------");

            if (item.content!=nil) {

                [title addObject:item.content];

            }
            i++;
        }
        else
        {
            NSLog(@"item is nil");
        }
    }
}
else
{
    NSLog(@"data is nil");
   // [title addObject:nil];
}