我正試圖在UITableview
中實現展開 - 摺疊功能。uibutton不會在uitableview中更改展開 - 摺疊功能的圖像objective-c
1)部分1: 含有2行
2)部分2: 包含3排
1)部分3: 含有2行
2)部分4: 含有2排
科有
UILabel
一個dUIButton
在他們看來。UIButton
有+的圖像和 - 時的「+」按鈕,用戶點擊該節得到了擴大和顯示的行和其他部分得到崩潰 和按鈕改變的圖像「 - 」當用戶點擊在部分的「 - 」按鈕上。本節得了collpase和按鈕改變形象「+」
但問題是,當我的「+」按鈕,單擊並重新加載UITableview
按鈕的圖像不得到改變。 請幫助我解決方案和適當的方式來實現展開和摺疊行。
- (IBAction)BtnSection_ExpandCollapseAction:(UIButton *)sender {
sectionselected = sender.tag; // remember which section is tapped
if(sender.selected){
Isopen = FALSE; // whether to expand or to collapse
sender.selected = false;
[sender setImage:[UIImage imageNamed:@"BtnPlus"] forState:UIControlStateNormal];
}else{
Isopen = TRUE;
sender.selected = TRUE;
[sender setImage:[UIImage imageNamed:@"btnMinus"] forState:UIControlStateNormal];
}
[self.tblView reloadData];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *HeaderView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-10, 35)];
HeaderView.backgroundColor = [UIColor lightGrayColor];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-80, 5, 50, HeaderView.frame.size.height-10)];
[btn setImage:[UIImage imageNamed:@"BtnPlus"] forState:UIControlStateNormal];
[btn addTarget:self
action:@selector(BtnSection_ExpandCollapseAction:)
forControlEvents:UIControlEventTouchUpInside];
btn.tag = section;
UILabel *LblHeader = [[UILabel alloc] initWithFrame:CGRectMake(20, 5,HeaderView.frame.size.width-10, HeaderView.frame.size.height-10)];
if(section == 0){
LblHeader.text = @"Chief Compalain";
}else if(section == 1){
LblHeader.text = @"Extra Oral";
}else if(section == 2){
LblHeader.text = @"Intra Oral";
}else if(section == 3){
LblHeader.text = @"Radiographical";
}
LblHeader.textColor = [UIColor whiteColor];
[HeaderView addSubview:LblHeader];
[HeaderView addSubview:btn];
return HeaderView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(Isopen){
if(section == sectionselected){
return 7;
}else{
return 0;
}
}else{
return 0;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
}