我正试图在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 {
}