in Renderer class-> FooPageRenderer : PageRenderer
private ProductDetailsPage _prodDetailsPage;
private ToolbarItem _tbi;
protected override void OnElementChanged(VisualElementChangedEventArgs e) {
base.OnElementChanged (e);
_prodDetailsPage = e.NewElement as ProductDetailsPage;
}
public override void ViewDidLoad() {
base.ViewDidLoad();
_tbi = _prodDetailsPage.ToolbarItems.Where (t => t.Name == "Share").FirstOrDefault();
_tbi.Activated += ShareProduct;
}
private void ShareProduct(object sender, EventArgs e) {
var shareItems = new List<NSObject> ();
shareItems.Add (new NSString("Some Title"));
var activityController = new UIActivityViewController (shareItems.ToArray (), null);
if(Class.GetHandle("UIPopoverPresentationController") != IntPtr.Zero && Device.Idiom == TargetIdiom.Tablet) {
activityController.PopoverPresentationController.BarButtonItem = _tbi.ToUIBarButtonItem();
}
PresentViewController (activityController, true, null);
}
Exception:
(GAIUncaughtExceptionHandler.m:49): Uncaught exception: UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x1852a070>) should have a non-nil sourceView or barButtonItem set before the presentation occurs
Question: How do I get a UIView for activityController.PopoverPresentationController.SourceView? I wish ToolBarItem _tbi inherits UIView, but it's not.
Thank you.