Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.ios 从通过设置Cell.Accessory添加的DetailDisclosure按钮显示UIPopoverController_Xamarin.ios_Uipopovercontroller_Monotouch.dialog_Uitableview - Fatal编程技术网

Xamarin.ios 从通过设置Cell.Accessory添加的DetailDisclosure按钮显示UIPopoverController

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

我有一个UITableView,我使用的方式与在Xamarin中演示的相同

根据示例中的说明,我在
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示例,它对你有用吗?@jonathanpeppers
accessorybutntaped
有效,我对Xamarin示例没有任何问题。我的问题是,仅将
GetCell
中的
cell.accessority
设置为
uitableviewCellAccessority.detailDisclosure按钮
不会在任何地方显示附件的视图
cell.AccessoryView
始终为空,并且似乎与我为
cell.Accessory
选择的任何类型都不相关。不过,我确实需要附件的视图,以便将UIPopoverController连接到它。你可以用一个
矩形f
来显示popover,你知道吗?@jonathanpeppers是的,但这不允许我显示UIPopupViewcontroller,它的箭头指向DetailDisclosure按钮,因为我不知道按钮的位置。你的评论确实给了我一个想法:)。见下文。我认为这很好。要抓住底层的
ui按钮
,而不在
子视图中循环,可能不是一个简单的方法。这似乎比试图在UI控件树中“查找”按钮更干净。