I Have one Screen in which i have to hide or show UITableview on button touch. This single button have two diffrent image which is change by button click.
I had tried with this code.
- (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;
}
}
And with this i set button manually
-(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;
}
But nothing works for me.
I also tried with Breakpoint but it wasn't calling my custom method.
Help
is greatly appreciated.