gpt4 book ai didi

ios - 在行的按钮附近添加一个 UIView?

转载 作者:行者123 更新时间:2023-11-29 13:06:14 26 4
gpt4 key购买 nike

我有包含部分和行的表格 View 。当用户单击行/部分内的按钮时,它将在该特定按钮附近显示 UIView

- (IBAction) openRoundedPopover:(id)sender {

btn = (UIButton*) sender;

//Identify if user clicked header section or cell row
if (btn.titleLabel.tag == 8)
isHeaderViewButtonClicked = YES; // headerview mean when user clicks on section
else
isHeaderViewButtonClicked = NO;

MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn.superview.superview;
CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView];

self.roundedButtonMenu.frame = CGRectMake(43, isHeaderViewButtonClicked ? hitPoint.y+50:clickedResourceCell.frame.origin.y+53, self.roundedButtonMenu.frame.size.width, self.roundedButtonMenu.frame.size.height);

[self.view addSubview:self.roundedButtonMenu];

}

这些都工作正常。但是,当用户继续添加行/部分并单击底部行/部分的按钮时(即将 tableview 滚动到底部以查看新添加的行/部分),它不会在该按钮附近显示 UIView。它会在其他地方弹出或根本不显示。

最佳答案

MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn.superview.superview; 

不要假定您无法控制 View 层次结构。 (这将在不久的 ios future 110% 中断)

所以我假设您没有得到单元格的框架!

MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn; 
while(clickedResourceCell.superview && ![clickedResourceCell isKindOfClass:[MainTableViewCell class]]) {
clickedResourceCell = (MainTableViewCell*)clickedResourceCell.superview;
}

但您的问题是您将按钮添加到不在 ScrollView 中的 elf.view 中。滚动时计算真的不起作用,是吗?

将其添加到单元格中:

button.frame = CGRectMake(0,0,100,40); //dummy
[cell.contentView addSubview:btw];
//take care of cell reusing!

关于ios - 在行的按钮附近添加一个 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18557919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com