从填充阵列的一个UITableView [英] Populating a UITableView from arrays
本文介绍了从填充阵列的一个UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用下面的code我使用hpple解析HTML帮助。
我需要利用数据帮助。
- (无效){什么
NSData的* htmlData = [[NSString的stringWithContentsOfURL:[NSURL URLWithString:@http://www.objectgraph.com/contact.html]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple * xpathParser = [[TFHpple页头] initWithHTMLData:htmlData];
NSArray的*标题= [xpathParser搜索:@// H3]; //获取页面标题 - 这是XPath符号
TFHppleElement *标题= [标题objectAtIndex:0];
* NSString的myTitles = [标题内容]NSArray的*文章= [xpathParser搜索:@// H4]; //获取页面的文章 - 这是XPath符号
TFHppleElement *文章= [文章objectAtIndex:0];
* NSString的myArtical = [文章内容]
我想创建并从数组填充表标题
然后可以点击桌子上的物品装入一个子视图应该相同指数显示相应的ARTICAL?
我想这样做编程或使用IB
任何人都可以提出一些样品code或A教程?
感谢。
解决方案
- (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分{返回[标题计数]}
- (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath { 静态的NSString * MyIdentifier = @MyIdentifier * UITableViewCell的细胞= [的tableView dequeueReusableCellWithIdentifier:MyIdentifier];
如果(细胞==零){
电池= [[[UITableViewCell的页头] initWithFrame:方法CGRectZero reuseIdentifier:MyIdentifier]自动释放];
}
cell.textLabel.text = [标题objectAtIndex:indexPath.row]; 返回细胞;}
- (无效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath {/ *这里弹出您与从数组索引indexpath.row数组对应值的子视图。* /}
I need help with the following code i am using hpple to parse html. and i need help utilizing the data.
-(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];
i want to create and populate a table from the array "titles" Then be able to click the item on the table to load a subview that should show the corresponding artical at the same index?
I'd like to do this programatically or using IB
can anyone suggest some sample code or a tutorial?
Thanks.
解决方案
- (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 ..*/
}
这篇关于从填充阵列的一个UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文