我需要以下代码的帮助,我正在使用hpple解析html。
我需要利用数据的帮助。

-(void) whatever{
NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *titles  = [xpathParser search:@"//h3"]; // get the page title - this is xpath     notation
TFHppleElement *title = [titles objectAtIndex:0];
NSString *myTitles = [title content];

NSArray *articles  = [xpathParser search:@"//h4"]; // get the page article - this is xpath     notation
TFHppleElement *article = [articles objectAtIndex:0];
NSString *myArtical = [article content];

我想从数组“titles”创建并填充表格
然后能够单击表上的项目以加载一个子视图,该子视图应在相同的索引处显示相应的文章?

我想以编程方式或使用IB进行此操作

谁能建议一些示例代码或教程?

谢谢。

最佳答案

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return [titles count];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{



        static NSString *MyIdentifier = @"MyIdentifier";

        UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
        if (cell == nil){
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
        }


    cell.textLabel.text = [titles objectAtIndex:indexPath.row];

        return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

/* here pop up Your subview with corresponding  value  from the array with array index indexpath.row ..*/

}

关于iphone - 从数组填充UITableView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4367393/

10-11 16:04