這是我的代碼,只是添加了影像,但在點擊按鈕時沒有改變。請建議一個作業代碼。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
const CGRect fr = CGRectMake(0, 0, 320.0, 40.0 );
btn = [[UIButton alloc]initWithFrame:fr];
UIImageView *imgArrow = [[UIImageView alloc]initWithFrame:CGRectMake(380, 2.5, 25, 25)];
imgArrow.image=[UIImage imageNamed:@"arrow.jpeg"];
[btn setTitle:[self tableView:tableView titleForHeaderInSection:section] forState:UIControlStateNormal ];
btn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
[btn setBackgroundColor:[UIColor redColor]];
[btn setTag:section];
[btn addSubview:imgArrow];
[btn addTarget:self action:@selector(sectionOpenToggle:) forControlEvents:UIControlEventTouchUpInside];
return btn;
}
uj5u.com熱心網友回復:
首先,按鈕已經有一個可以使用的影像視圖,所以不要這樣做:
[btn addSubview:imgArrow];
相反,請執行以下操作:
[btn setImage:[UIImage imageNamed:@"arrow.jpeg"] forState:UIControlStateNormal];
然后,在您的sectionOpenToggle方法中(假設它看起來像這樣),更改影像:
- (void)sectionOpenToggle:(UIButton *)sender {
[sender setImage:[UIImage imageNamed:@"other-arrow.jpeg"] forState:UIControlStateNormal];
// whatever else you want to do
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/482398.html
