{"record":{"id":"bbf24c645968b76e","repo":"dotnet/maui","slug":"no-uiviewcontroller-found-to-present-bbf24c","errorCode":null,"errorMessage":"No UIViewController found to present.","messagePattern":"No UIViewController found to present\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs","lineNumber":349,"sourceCode":"\t\t\t\t\tcontinue;\n\n\t\t\t\tvar item = _cell.ContextActions[i];\n\t\t\t\tvar weakItem = new WeakReference<MenuItem>(item);\n\t\t\t\tvar action = UIAlertAction.Create(item.Text, UIAlertActionStyle.Default, a =>\n\t\t\t\t{\n\t\t\t\t\tif (_scroller == null)\n\t\t\t\t\t\treturn;\n\n\t\t\t\t\t_scroller.SetContentOffset(new PointF(0, 0), true);\n\t\t\t\t\tif (weakItem.TryGetTarget(out MenuItem mi))\n\t\t\t\t\t\t((IMenuItemController)mi).Activate();\n\t\t\t\t});\n\t\t\t\tactionSheet.AddAction(action);\n\t\t\t}\n\n\t\t\tvar controller = GetController();\n\t\t\tif (controller == null)\n\t\t\t\tthrow new InvalidOperationException(\"No UIViewController found to present.\");\n\n\t\t\tif (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone || (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && actionSheet.PopoverPresentationController == null))\n\t\t\t{\n\t\t\t\tvar cancel = UIAlertAction.Create(StringResources.Cancel, UIAlertActionStyle.Cancel, null);\n\t\t\t\tactionSheet.AddAction(cancel);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (actionSheet.PopoverPresentationController != null)\n\t\t\t\t{\n\t\t\t\t\tactionSheet.PopoverPresentationController.SourceView = _tableView;\n\t\t\t\t\tactionSheet.PopoverPresentationController.SourceRect = sourceRect;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcontroller.PresentViewController(actionSheet, true, null);\n\t\t}\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs#L331-L367","documentation":"Thrown by the iOS ContextActionCell when GetController() returns null, meaning no UIViewController could be located up the view hierarchy to present the action sheet for context actions. On iPhone/iPad the action sheet (UIAlertController) requires a presenting view controller.","triggerScenarios":"Triggering context actions on a cell whose view is not currently attached to a window/view-controller hierarchy (e.g. measured off-screen, in a detached window, or during teardown). Presenting context actions before the view is on screen. Window/hierarchy not yet established at activation time.","commonSituations":"Activating context actions during view recycling or before the page is fully presented. Cells inside a popover/secondary window whose controller chain is incomplete. Programmatic activation of a menu item before navigation completes.","solutions":["Ensure context actions are only user-triggered after the page is fully presented and on screen.","Delay activation until UIApplication.SharedApplication.KeyWindow.RootViewController is available.","Avoid invoking context actions during lifecycle transitions (appearing/disappearing)."],"exampleFix":"// before\nawait Task.Run(() => menuItem.Activate()); // cell not yet on screen\n\n// after\nawait Page.Appeared;\n((IMenuItemController)menuItem).Activate();","handlingStrategy":"validation","validationCode":"// Only activate context actions once the cell is attached to a window\nif (GetController() is null) return; // not yet presentable","typeGuard":null,"tryCatchPattern":"try { ((IMenuItemController)menuItem).Activate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No UIViewController\"))\n{ /* defer until the page is presented */ }","preventionTips":["Trigger context actions only from user interaction after the page is on screen.","Avoid programmatic activation during lifecycle transitions.","Ensure the view hierarchy is attached before presenting sheets."],"tags":["maui","listview","ios","context-actions","uiviewcontroller","lifecycle"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}