2012-03-13 90 views
1

我已經在tableview中使用- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section對部分進行了自定義視圖,但是在iam重新加載tableview的部分點擊了按鈕時。它爲該部分重新加載表格,但其餘部分未顯示。顯示或隱藏行在表視圖中點擊部分時

我不知道該怎麼做。代碼- (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 2012-03-13 06:34:32

+0

約翰阿布魯齊:嘿魚febonchi大聲笑哪裏..這可能會幫助您先生http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html – 2012-03-13 07:06:56

+3

https://developer.apple.com/library /ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139 - 這可能會對您有所幫助。 – 2012-03-13 08:45:10

回答

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; 
} 

試試這個。它可能會幫助你。

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; 
} 

根據你的代碼if (!selected)然後headerView獲得分配的其他明智的,不要。 因此,在if條件之前執行分配工作正如@jyotishree提到的那樣。