{"record":{"id":"e10d0642286c6e41","repo":"dotnet/maui","slug":"no-uiviewcontroller-found-to-present","errorCode":null,"errorMessage":"No UIViewController found to present.","messagePattern":"No UIViewController found to present\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/ContextActionCell.cs","lineNumber":340,"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":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/ContextActionCell.cs#L322-L358","documentation":"ContextActionCell throws InvalidOperationException(\"No UIViewController found to present.\") when its controller-walk returns null. iOS requires a UIViewController to present a UIAlertController for context actions; if the cell is not attached to any window/view hierarchy, no controller can be located and the action sheet cannot be shown.","triggerScenarios":"Activating context actions on a cell whose ViewCell/ListView is not yet in a windowed UIViewController hierarchy; calling Activate on a MenuItem for a cell that was detached, recycled, or never displayed.","commonSituations":"Programmatically triggering a MenuItem.Activate() outside the live UI; cells recycled while a context action is still pending; modal transitions detaching the view; tests invoking context actions without a hosted controller.","solutions":["Only trigger context actions after the cell's ListView is visible in a windowed UIViewController.","Cancel pending context actions on cell recycling/detachment.","In tests/hosted scenarios, ensure the page is presented before invoking context action menu items."],"exampleFix":"// before\n((IMenuItemController)menuItem).Activate();\n// after\nif (GetController(cell) != null)\n    ((IMenuItemController)menuItem).Activate();","handlingStrategy":"validation","validationCode":"// Ensure a controller exists before activating context actions.\nvar controller = FindViewController(cell);\nif (controller == null) return; // not yet presented","typeGuard":"static bool IsCellPresented(UITableViewCell cell) =>\n    cell.Window != null && FindViewController(cell) != null;","tryCatchPattern":null,"preventionTips":["Trigger context actions only when the ListView is visible in a window.","Cancel pending context actions on cell recycle.","Avoid invoking MenuItem.Activate outside the live UI."],"tags":["maui","xamarin-forms","ios","context-actions","uiviewcontroller","invalidoperation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}