2011-12-06 10 views
0

を呼び出す.....次デリゲートメソッドを使用しています、私はUIViewController..IでのUITableViewで働いているのuitableビューのデリゲートメソッド

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

私はビューをロードしたら、私は呼ばれているすべてのデリゲートを見つけます。 ....しかし、私は.....ボタンクリックで、私は、このようにしてみました
を....これらのメソッドを呼び出す必要が

[self tableView:table numberOfRowsInSection:rows]; 
[self tableView:table cellForRowAtIndexPath:path]; 

私は、これらのメソッドが呼び出されていることがわかりますが、何も起こりませんでした(これらの代理人の中のコードは動作しません)....私はなぜかknwをしないでください???助言がありますか???

+0

これらのデリゲートメソッドを直接呼び出すことは想定されていません。これらのデリゲートメソッドを実装すると、テーブルビューで呼び出すことができるため、表示する必要がある情報を尋ねることができます。 「うまくいかない」とは何かを定義してください - 見たいと思われるものは何ですか? – jrturton

答えて

0

それはあなたのソリューションにテーブルビュー

[self.tableView reloadData]; 

または完全なコードのすべてのデリゲートを呼び出しますボタンクリック関数内のコードを書くである: -

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


    static NSString *CellIdentifier = @"Cell"; 

    customCell *cell = [[customCell alloc]init]; 
    if (cell == nil) { 
     cell = [[[customCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell 
    cell.selectionStyle = UITableViewCellSelectionStyleBlue; 


    NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil]; 
    cell = (customCell *)[topLevelObjects objectAtIndex:0]; 


    int count=0; 
    for(id currentObject in topLevelObjects) 
    { 
     count++; 
     if([currentObject isKindOfClass:[customCell class]]) 
     { 

      cell= (customCell *)currentObject; 

      UILabel *sName = (UILabel *)[cell.contentView viewWithTag:1]; 

      //Checking the flag that is set in the btnClicked event 
      if (flag) { 
        sName.hidden=YES; 
       } 

       else{ 
       sName.text = [arrayResult objectAtIndex:indexPath.row];    
       } 

     } 
    } 

    return cell; 
    [topLevelObjects release]; 
    [cell release]; 

} 

-(IBAction) btnClicked:(id) sender{ 
flag=YES; 
[self.tableView reloadData]; 
} 

は、それが動作します、これを試してみてください。

+0

ありがとうございます。 – Icoder

+0

もう1つのクエリ....テーブルの各セルの内側にラベルがあります。テーブルをリロードしているときに、すべてのラベルが削除されません。クリック – Icoder

+0

私はあなたがカスタムセルを持っていると思います...テーブルをリロードする前にブールフラグ= YESを適用します。あなたのcellAtRowAtIndexPath内部では、uitableviewのデリゲートがフラグをチェックします(yesの場合)。 –

関連する問題