我很难从tableviewCell的annexButton正确显示弹出框。
我不使用附件视图的原因是因为该单元格处于编辑模式,并且无法同时显示绿色加号+自定义附件视图。.也许我忽略了前面的内容?
目前,我的弹出窗口可以正确显示,但是对于这种配置,只有这种情况,因为我设置了与原点的静态距离...任何想法如何解决呢?
码:
-(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];
}
最佳答案
此线程中的这段代码对我有帮助:How to correctly present a popover from a UITableViewCell with UIPopoverArrowDirectionRight or UIPopoverArrowDirectionLeft
感谢rachels提示
UIView *accessoryView = cell.accessoryView; // finds custom accesoryView (cell.accesoryView)
if (accessoryView == nil) {
UIView *cellContentView = nil;
for (UIView *accView in [cell subviews]) {
if ([accView isKindOfClass:[UIButton class]]) {
accessoryView = accView; // find generated accesoryView (UIButton)
break;
} else if ([accView isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) {
// find generated UITableViewCellContentView
cellContentView = accView;
}
}
// if the UIButton doesn't exists, find cell contet view (UITableViewCellContentView)
if (accessoryView == nil) {
accessoryView = cellContentView;
}
// if the cell contet view doesn't exists, use cell view
if (accessoryView == nil) {
accessoryView = cell;
}
}