gpt4 book ai didi

ios - 从单元格附件按钮呈现弹出窗口?

转载 作者:行者123 更新时间:2023-12-01 16:04:46 24 4
gpt4 key购买 nike

我很难从 tableviewCell 的附件按钮正确呈现弹出框。

我不使用附件 View 的原因是因为单元格处于编辑模式,我无法同时显示绿色加号 + 自定义附件 View 。也许我忽略了前面的一些东西?

目前我的弹出框显示正确,但这只是这种配置的情况,因为我设置了与原点的静态距离......任何想法如何解决这个问题?

代码:

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

if (![self duplicateDayContent]) {
duplicateDayContent = [[self storyboard]instantiateViewControllerWithIdentifier:@"CopyDay"];
[duplicateDayContent setDelegate:self];

duplicateDayPopover = [[UIPopoverController alloc]initWithContentViewController:duplicateDayContent];
duplicateDayPopover.popoverContentSize = CGSizeMake(320, 600);

}

CGRect rect = CGRectMake(cell.bounds.origin.x+800, cell.bounds.origin.y+10, 50, 30);

[duplicateDayPopover presentPopoverFromRect:rect inView:cell permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

}

最佳答案

这对于具有 accessoryType .detailDisclosureButton 的单元格非常有效。 :

if let ppc = vc.popoverPresentationController, let cell = tableView.cellForRow(at: indexPath) {
ppc.sourceView = cell
ppc.sourceRect = CGRect(x: cell.bounds.width - 58, y: cell.bounds.height/2 - 11, width: 22, height: 22)
vc.modalPresentationStyle = .popover
}
present(vc, animated: true, completion: nil)

您通常会在 tableView(_ accessoryButtonTappedForRowWith indexPath:) 中执行此操作

您还可以使用标记测试计算帧的位置:
let marker = UIView(frame: ppc.sourceRect)
marker.backgroundColor = UIColor.red.withAlphaComponent(0.2)
cell.addSubview(marker)

Test marker

关于ios - 从单元格附件按钮呈现弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16751909/

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