gpt4 book ai didi

iphone - 从数组填充 UITableView

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:34:41 25 4
gpt4 key购买 nike

我需要以下代码的帮助,我正在使用 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”中创建并填充一个表然后能够单击表格上的项目以加载应在同一索引处显示相应文章的 subview ?

我想以编程方式或使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com