Ben Reeves가 HTMLParser를 사용 중입니다. 그것은 위대한 작품이지만 유일한 문제는 내가 UITableView에 출력을 넣을 수 없다는 것입니다. 누구든지이 코드의 문제점을 알 수 있습니까? .................................................. .................................UITableView에서 파싱 된 결과
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSError *error = nil;
NSURL *url=[[NSURL alloc] initWithString:@"http://website.com/"];
NSString *strin=[[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
HTMLParser *parser = [[HTMLParser alloc] initWithString:strin error:&error];
if (error) {
NSLog(@"Error: %@", error);
return;
}
HTMLNode *bodyNode = [parser body];
NSArray *divNodes = [bodyNode findChildTags:@"div"];
for (HTMLNode *inputNode in divNodes) {
if ([[inputNode getAttributeNamed:@"class"] isEqualToString:@"views-field-title"]) {
NSLog(@"%@", [inputNode allContents]);
listData = [[NSArray alloc] initWithObjects:[inputNode allContents], nil];
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
@end
사용할 수 있습니까? HTML 데이터를 테이블에 어떻게 표시 하시겠습니까? –
UITableView 이벤트 목록을 갖고 싶어하지만 tableview는 배열의 마지막 하나만 보여줍니다. 나는 [inputNode allContents]를 배열로 취급하고 그것을 "cell.textLabel.text = [listData objectAtIndex : row]"에 넣으려고합니다. 콘솔에서는 이벤트 목록을 표시하지만 셀의 마지막 이벤트 만 표시합니다. 나는 뭔가를 놓칠지도 모른다. 무엇을 모른다 ... – Benjamen