Xamarin.ios 从通过设置Cell.Accessory添加的DetailDisclosure按钮显示UIPopoverController
我有一个UITableView,我使用的方式与在Xamarin中演示的相同 根据示例中的说明,我在Xamarin.ios 从通过设置Cell.Accessory添加的DetailDisclosure按钮显示UIPopoverController,xamarin.ios,uipopovercontroller,monotouch.dialog,uitableview,Xamarin.ios,Uipopovercontroller,Monotouch.dialog,Uitableview,我有一个UITableView,我使用的方式与在Xamarin中演示的相同 根据示例中的说明,我在GetCell方法中将cell.accessority设置为detaildisclosure按钮,如下所示: public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { (Some code to create/style the
GetCell
方法中将cell.accessority
设置为detaildisclosure按钮
,如下所示:
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
(Some code to create/style the cell, etc. See tutorial link.)
cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton;
}
public override void AccessoryButtonTapped (UITableView tableView, NSIndexPath indexPath)
{
uipoc = new UIPopoverController(uivc);
uipoc.PopoverContentSize = new SizeF(200f, 300f);
uipoc.PresentFromRect (tableView.CellAt (indexPath).AccessoryView.Frame, tableView, UIPopoverArrowDirection.Right, true);
}
我想要一个uipopcovercontroller
在点击detaildisclosure按钮时显示。它的锚需要“连接”到按钮上
为此,我需要相应地更改AccessoryButtonTapped
方法,如下所示:
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
(Some code to create/style the cell, etc. See tutorial link.)
cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton;
}
public override void AccessoryButtonTapped (UITableView tableView, NSIndexPath indexPath)
{
uipoc = new UIPopoverController(uivc);
uipoc.PopoverContentSize = new SizeF(200f, 300f);
uipoc.PresentFromRect (tableView.CellAt (indexPath).AccessoryView.Frame, tableView, UIPopoverArrowDirection.Right, true);
}
Uipoc
是一个类变量,与(仍然为空)UIViewController uivc
一样
据我所知,PresentFromRect
的第一个参数确定UIPopoverController“连接”到的UIView,它需要该视图的Frame属性来完成此操作
不幸的是,我上面做的方式不起作用cell.AccessoryView
始终为空,即使我已将cell.Accessory
设置为DetailDispositionButton
答案表明设置单元格.accessority
不会影响单元格.AccessoryView
属性(我知道它处理ObjectiveC,但我想这同样适用于MonoTouch)
相反,建议通过将ui按钮
分配给cell.AccessoryView
手动添加detaildisclosure按钮
。但是,这意味着我不能使用Xamarin示例中的AccessoryButtonTapped
方法,需要创建自己的eventhandler,等等
作为替代方案,我尝试在单元格的子视图中循环,并像这样连接popovercontroller:
uipoc.PresentFromRect (tableView.CellAt(indexPath).Subviews[1].Frame, tableView, UIPopoverArrowDirection.Right, true);
但是,使用子视图[0]
和子视图[2]
,它根本不起作用,而子视图[1]
会给我奇怪的结果-无论点击了哪个单元格的按钮,弹出菜单总是显示在表中第一个单元格的详细披露按钮的旁边
我的问题:
如果仅将单元格.accessory
设置为UITableViewCellAccessory.detailDispositionButton
,是否有办法获取DetailDispositionButton
的视图(即附件视图)
如果不是,后一种解决方案(手动添加ui按钮
)是实现我想要的唯一方法吗?我如何在C#/MonoTouch中实现这一点
谢谢 在做了一些修改之后,我发现了一个有点难看但有效的解决方法:
public override void AccessoryButtonTapped (UITableView tableView, NSIndexPath indexPath)
{
uipoc = new UIPopoverController(uivc);
uipoc.PopoverContentSize = new SizeF(200f, 300f);
uipoc.PresentFromRect (new RectangleF(cell.Frame.Right - 40f, cell.Frame.Y, cell.Frame.Width, cell.Frame.Height), tableView, UIPopoverArrowDirection.Right, true);
}
我不需要附件的框架中的位置信息
,而是使用单元格本身的信息,并从右侧减去40。这将在该单元格中的detaildisclosure按钮
左侧显示UIPopupViewcontroller
,其箭头指向该按钮。显然,您需要为正确的维度减去(或加)40,这取决于您选择的UIPopoverArrowDirection
我怀疑这是正确的方法,尽管我想我会坚持下去,除非有人提出更好的建议。你需要弄清楚为什么accessorybuttonattaped
不起作用。与Xamarin样品有什么不同?如果您在UITableViewCell
上设置了附件
,并且它不是None
,则它应该触发该消息。如果你运行Xamarin示例,它对你有用吗?@jonathanpeppersaccessorybutntaped
有效,我对Xamarin示例没有任何问题。我的问题是,仅将GetCell
中的cell.accessority
设置为uitableviewCellAccessority.detailDisclosure按钮
不会在任何地方显示附件的视图cell.AccessoryView
始终为空,并且似乎与我为cell.Accessory
选择的任何类型都不相关。不过,我确实需要附件的视图,以便将UIPopoverController连接到它。你可以用一个矩形f
来显示popover,你知道吗?@jonathanpeppers是的,但这不允许我显示UIPopupViewcontroller,它的箭头指向DetailDisclosure按钮,因为我不知道按钮的位置。你的评论确实给了我一个想法:)。见下文。我认为这很好。要抓住底层的ui按钮
,而不在子视图中循环,可能不是一个简单的方法。这似乎比试图在UI控件树中“查找”按钮更干净。