到目前为止,我有这个:
我正在尝试使用网页中的 hpple 解析日期,然后将其显示在标签中。我不知道该怎么做。我想我必须使 void GoToSecretsList 中的 Secret 变量以某种方式等于另一个 void 得到的值......有人有什么建议吗?
- (void)GoToSecretsList
{
UIViewController *vc;
vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecretsListID"];
[self.navigationController pushViewController:vc animated:YES];
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 120, 500, 40)];
[myLabel setBackgroundColor:[UIColor clearColor]];
NSString *Secret;
Secret = @"Get value from website";
[myLabel setText:[NSString stringWithFormat:@"#1: %@", Secret]];
[[vc view] addSubview:myLabel];
}
-(void)LoadSecrets {
// 1
NSURL *SecretsUrl = [NSURL URLWithString:@"http:/removed.com/xlxlx"];
NSData *SecretsHtmlData = [NSData dataWithContentsOfURL:SecretsUrl];
// 2
TFHpple *secretsParser = [TFHpple hppleWithHTMLData:SecretsHtmlData];
// 3
NSString *secretsXpathQueryString = @"/secret";
NSArray *secretsNodes = [secretsParser searchWithXPathQuery:secretsXpathQueryString];
// 4
NSMutableArray *newSecrets = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in secretsNodes) {
// 5
VOI *secret = [[VOI alloc] init];
[newSecrets addObject:secret];
// 6
secret.title = [[element firstChild] content];
// 7
secret.url = [element objectForKey:@"href"];
}
}
编辑:现在我只有这个:
- (void)GoToSecretsList
{
UIViewController *vc;
vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecretsListID"];
[self.navigationController pushViewController:vc animated:YES];
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 120, 500, 40)];
[myLabel setBackgroundColor:[UIColor clearColor]];
NSURL *SecretsUrl = [NSURL URLWithString:@"http://removed.com/dsdsds"];
NSData *SecretsHtmlData = [NSData dataWithContentsOfURL:SecretsUrl];
TFHpple *secretsParser = [TFHpple hppleWithHTMLData:SecretsHtmlData];
NSString *secretsXpathQueryString = @"/secret";
NSArray *secretsNodes = [secretsParser searchWithXPathQuery:secretsXpathQueryString];
[myLabel setText:[NSString stringWithFormat:@"#1: %@", secretsNodes]];
[[vc view] addSubview:myLabel];
}
但是什么变量有信息..?或者我做错了什么?因为 secretNodes 不是。