2012-03-13 87 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提到的那样。