2012-03-13 17 views
1

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionを使用してテーブルビューのセクションのカスタムビューを作成しましたが、ボタンがセクションiamの再ロードテーブルビューでタップされたときにカスタムビューを作成しました。そのセクションのテーブルがリロードされますが、残りのセクションは表示されません。セクションがテーブルビューでタップされている行の表示または非表示

私はこれを行う方法がわかりません。 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionのコードは

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

if (!selected) { 

    headerView = [[[HeaderView alloc] initWithFrame:HeaderFrame] autorelease]; 

    headerView.backgroundColor = [UIColor greenColor]; 

    headerView.label.text = @"title"; 

    headerView.button.tag = section; 

    headerView.tag = section; 

    [headerView.button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

    return headerView; 
} 
else if (selectedIndex == section && selected){ 

    [headerView.button setImage:[UIImage imageNamed:@"Croped-Rotated.png"] forState:UIControlStateNormal]; 

    return headerView; 
} 
else 
    return headerView; 
} 

です。何か助けていただければ幸いです。

+0

あなたがしたいことを正確に説明できますか? – Rupesh

+0

John Abruzzi:えええええええええええええええええええええええええええええええええ投稿ありがとうございますhttp://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html –

+3

https://developer.apple.com/library /ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139 - これが役に立ちます。 –

答えて

0
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 



    headerView = [[[HeaderView alloc] initWithFrame:HeaderFrame] autorelease]; 

    headerView.backgroundColor = [UIColor greenColor]; 

    headerView.label.text = @"title"; 

    headerView.button.tag = section; 

    headerView.tag = section; 

    [headerView.button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

if (selectedIndex == section && selected){ 

    [headerView.button setImage:[UIImage imageNamed:@"Croped-Rotated.png"] forState:UIControlStateNormal]; 

    return headerView; 
} 
else 
    return headerView; 
} 

これを試してください。それはあなたを助けるかもしれません。あなたのコードif (!selected)を1として

0
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

if (!selected) { 

    headerView = [[[HeaderView alloc] initWithFrame:HeaderFrame] autorelease]; 

    headerView.backgroundColor = [UIColor greenColor]; 

    headerView.label.text = @"title"; 

    headerView.button.tag = section; 

    headerView.tag = section; 

    [headerView.button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

    return headerView; 
} 
else if (selectedIndex == section && selected){ 

    [headerView.button setImage:[UIImage imageNamed:@"Croped-Rotated.png"] forState:UIControlStateNormal]; 

    return headerView; 
} 
else 
    return headerView; 
} 

その後、headerViewは賢明でない他割り当てられます。 したがって、ifの条件の前に割り当て作業を実行してください。

関連する問題