簡體   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