2010-12-06 10 views
2

次のコードで助けが必要です。hppleを使ってhtmlを解析しています。 と私はデータを利用する助けが必要です。配列からUITableViewを取り込む

-(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]; 

私は同じインデックスに対応するarticalを示すべきサブビューをロードするために、テーブルの上の項目をクリックすることができ、配列「タイトル」 からテーブルを作成し、移入したいですか?

私はプログラム的または使用してIB

これを実行したい

誰でもいくつかのサンプルコードやチュートリアルを提案することができますか?

ありがとうございました。一般的なアプローチとして

答えて

4
- (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 ..*/ 

} 
+0

それは素晴らしいrajesh、これは私のためのテーブルを作成するか、私はインターフェイスビルダーでこれをtableviewを作成する必要がありますか?私はこれらを呼び出す必要がありますか? IOS dev –

+0

の新しい私の無知のために申し訳ありませんあなたdidloadのテーブルビューを作成する必要はありません。 – rajesh

+1

あなたの.hファイルをdidload .inにテーブルビューを作成する必要はありません。UITbaleView * yourtableView; viewDidLoadメソッドの下に.mファイルを置く。yourtableView = [[UITableView alloc] initWithFrame:CGRectMake:(自分の座標を置く)]; yourtableView.delegate = selfです。 [self.view addSubView:あなたのテーブルビュー];私の答えはint UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 'tableView'をyourTableViewに置き換えます。 k?もし私の質問があればお知らせください。 – rajesh

1

、あなたは、単に問題でのUITableViewのための代理人として、関連するコントローラクラスを設定して、次のメソッドを実装する必要があります。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

をしかし、私はAppleのTable View Programming guideを読んでお勧めします - シンプルなコードサンプルよりもはるかに解明され、それに従うのがかなり簡単です。

これを実行したら、まだサンプルコードの後に​​ある場合は、UITableView Class referenceの「関連するサンプルコード」セクションにプロジェクトの1つをダウンロードしてください。 (あなたはXcodeで、Appleのドキュメントビューア内これを行う場合、それはなど、ダウンロードを自動化し、あなたのためのXcodeでプロジェクトを開きます。)

0

まず、あなたはどこ.hファイルにUITableViewDelegateとUITableViewDatasourceを設定する必要がありますあなたはテーブルビューを作成し、テーブル値を格納するNSarrayを宣言し、viedidload関数の.mファイルにオブジェクトを持つ配列を初期化する必要があります(arr_name = [NSArray alloc] initwith オブジェクト:@ "one"、@ "two" 、nilの)あなたはこれらの3つのメソッドを配置する必要があり

  • (NSInteger)のtableView:(のUITableView *)のtableView numberOfRowsInSection:(NSInteger)セクション
  • (UITableViewCellの*)のtableView:(のUITableView *)のtableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

  • (無効)にtableView:(のUITableView *)のtableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

関連する問題