简体   繁体   中英

Access section header button in tableview when user clicks on a row of that section?

I want to access a button of a section header when user clicks on row in tableview . I can get clicked row number and that particular section by using NSIndexpath (ie section 1 - row 0 etc.), but could not retrieve button in the section header. I've tried using isKindOfClass by iterate through tableview , but did not work.

    MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn.superview.superview;
    clickedResourceCell.customThresholdBar.value = slider.value/100;
    NSIndexPath *indexpath = [self.tableView indexPathForCell:clickedResourceCell];

    [btn setTitle:[NSString stringWithFormat:@"%i%@", [[NSNumber numberWithFloat:[(UISlider *)sender value]] intValue], @"%"] forState:UIControlStateNormal];
    self.sliderValueLabel.text = [NSString stringWithFormat:@"%i%@", [[NSNumber numberWithFloat:[(UISlider *)sender value]] intValue], @"%"];

I've got row's button updated.Now want to update section.I've tried like this!

for(UIView *view in [self.tableView subviews])
    {
        if([view isKindOfClass:[UIButton class]])
        {
            UIButton *bttn = (UIButton *)view;
            if (bttn.titleLabel.tag == 7) {
                if (bttn.tag == indexpath.section) {
                    NSLog(@"FOUND");
                    [bttn setTitle:[NSString stringWithFormat:@"%i%@", completedAmount/i, @"%"] forState:UIControlStateNormal];
                }
            }

        }
    }

Do it this way:

UIView *sectionHeader = [tableView headerViewForSection:indexPath.section]; 
UIButton *button = (UIButton*)[sectionHeader viewWithTag:<button's tag>];

whenever you have the indexpath of the row. Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM