当用户点击tableview
中的行时,我想访问部分标题的按钮。我可以使用NSIndexpath
(即第1部分 - 第0行等)获取单击的行号和特定部分,但无法在部分标题中检索按钮。我已尝试通过isKindOfClass
迭代使用tableview
,但无效。
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];
}
}
}
}
答案 0 :(得分:2)
这样做:
UIView *sectionHeader = [tableView headerViewForSection:indexPath.section];
UIButton *button = (UIButton*)[sectionHeader viewWithTag:<button's tag>];
每当你有行的索引路径时。 祝你好运!