繁体   English   中英

当用户单击该部分的一行时,是否可以访问tableview中的部分标题按钮?

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

当用户单击tableview行时,我想访问节标题的按钮。 我可以通过使用NSIndexpath (即第1部分-第0行等)来获得被单击的行号和该特定部分,但是无法获取部分标题中的按钮。 我尝试通过tableview迭代使用isKindOfClass ,但是没有用。

    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], @"%"];

我已经更新了行的按钮。现在要更新部分。我已经尝试过了!

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];
                }
            }

        }
    }

这样做:

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

只要您具有该行的索引路径。 祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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