1

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 (i.e. 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];
                }
            }

        }
    }
4

1 回答 1

2

这样做:

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

每当您拥有该行的索引路径时。祝你好运!

于 2013-08-30T04:51:28.753 回答