在按钮上隐藏/显示UITableView

时间:2013-02-14 09:53:56

标签: cocoa-touch uitableview uibutton xcode4.5 ios6.1

我有一个屏幕,我必须在按钮触摸时隐藏或显示UITableview。 这个单个按钮有两个不同的图像,通过按钮点击更改。

我尝试过这段代码。

- (void)collapseOrExpandButtonPressed:(UIButton *)sender
{
      int i = [sender.titleLabel.text intValue];

NSNumber *numb;
if(i == 0)
{
    numb = [NSNumber numberWithBool:NO];
    sender.titleLabel.text = @"1";
    [sender setImage:[UIImage imageNamed:@"down.png"] forState:UIControlStateNormal];
    [sender setImage:[UIImage imageNamed:@"up.png"] forState:UIControlStateHighlighted];
    tView.hidden = YES;
}
else
{
    numb = [NSNumber numberWithBool:YES];
    sender.titleLabel.text = @"0";
    [sender setImage:[UIImage imageNamed:@"up.png"] forState:UIControlStateNormal];
    [sender setImage:[UIImage imageNamed:@"down.png"] forState:UIControlStateHighlighted];
    tView.hidden = NO;
}


}

用这个我手动设置按钮

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *a = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 62)];
a.backgroundColor = [UIColor clearColor];

[self.view addSubview:a];
button = [[UIButton alloc] initWithFrame:CGRectMake(240, 20, 30, 30)];

[button addTarget:self action:@selector(collapseOrExpandButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

button.tag = section;


if(button.tag != section)
{
    [button setImage:[UIImage imageNamed:@"down.png"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"up.png"] forState:UIControlStateHighlighted];
    button.titleLabel.text = @"0";
}
else
{
    [button setImage:[UIImage imageNamed:@"up.png"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"down.png"]      forState:UIControlStateHighlighted];
    button.titleLabel.text = @"1";
}

[a addSubview:button];
return a;

}

但是没有什么对我有用。

我也尝试使用Breakpoint,但它没有调用我的自定义方法。

Help非常感谢。

0 个答案:

没有答案