Skip to content

"Delegate Event handler" on native objects aren't invoked #24262

Closed

Description

@tipa

Apple platform

iOS & macOS

Framework version

net10.0-*

Affected platform version

.NET 10 - Xcode 26.1

Description

After updating to .NET10 GA and the Xcode 26.1 workload, some event handlers that forward Delegate events aren't invoked any more. The problem did not happen on .NET10 RC2 with Xcode 26.0.

I noticed this on iOS for UIDocumentPickerViewController and on macOS for NSTextField, but more classes might be affected

Steps to Reproduce

var picker = new UIDocumentPickerViewController([UTTypes.Zip], true);
picker.WasCancelled += (_, _) => System.Diagnostics.Debugger.Break();
picker.DidPickDocumentAtUrls += (_, _) => System.Diagnostics.Debugger.Break();
vc.PresentViewController(picker, true, null);
var field = new NSTextField();
field.Changed += (_, _) => System.Diagnostics.Debugger.Break();

NOTE: The problem does not happen when debugging a macOS app or an iOS app on the simulator.
However, the problem does happen when the macOS app has been built in Release mode or the iOS app runs on a physical device.

Did you find any workaround?

When setting the delegate myself and implementing the delegate method, this works as expected

Activity

  1. added
    regression
    on Nov 17, 2025
  2. self-assigned this
    on Nov 17, 2025
  3. added this to the xcode26.2 milestone on Nov 17, 2025
  4. added
    bug
    on Nov 17, 2025
  5. rolfbjarne commented on Nov 17, 2025

    @rolfbjarne
    Member

    I can reproduce this, and I'll have a look.

  6. tipa commented on Nov 17, 2025

    @tipa
    Author

    Thanks! If it helps tracking down the issue, UITabBarControllerDelegate events appears to be affected as well

  7. hflexgrig commented on Nov 17, 2025

    @hflexgrig

    UITabBarControllerDelegate

    Could you please share code sample how do you make working workaround? I need on my app asap workaround for Editor TextChanged event.

    This is gen AI generated code I'm trying to test

    
    using Foundation;
    using Microsoft.Maui.Handlers;
    using UIKit;
    
    namespace YourNamespace;
    
    public partial class CustomEditorHandler : EditorHandler
    {
        private TextViewDelegate? _delegateRef;
    
        protected override void ConnectHandler(UITextView platformView)
        {
            base.ConnectHandler(platformView);
    
            // Keep strong reference so linker/GC doesn't eat it in Release
            _delegateRef = new TextViewDelegate(this);
    
            // Override any existing delegate
            platformView.Delegate = _delegateRef;
        }
    
        protected override void DisconnectHandler(UITextView platformView)
        {
            if (platformView.Delegate == _delegateRef)
                platformView.Delegate = null;
    
            _delegateRef = null;
    
            base.DisconnectHandler(platformView);
        }
    
        private sealed class TextViewDelegate : UITextViewDelegate
        {
            private readonly CustomEditorHandler _handler;
    
            public TextViewDelegate(CustomEditorHandler handler)
            {
                _handler = handler;
            }
    
            // Called every time text actually changes
            public override void Changed(UITextView textView)
            {
                var virtualView = _handler.VirtualView;
                if (virtualView is null)
                    return;
    
                // Sync platform -> virtual view
                if (virtualView.Text != textView.Text)
                {
                    virtualView.Text = textView.Text;
    
                    // Notify MAUI the Text property has updated
                    _handler.UpdateValue(nameof(Editor.Text));
                }
            }
    
            // Optional: if you need to intercept keystrokes before they apply
            public override bool ShouldChangeText(UITextView textView, NSRange range, string text)
            {
                // You can add custom logic here if needed.
                // Returning true allows the change.
                return true;
            }
        }
    }
    
    
  8. rolfbjarne commented on Nov 17, 2025

    @rolfbjarne
    Member

    Adding this to the csproj should work around it:

    <PropertyGroup>
        <AppBundleExtraOptions>--optimize=-register-protocols</AppBundleExtraOptions>
    </PropertyGroup>
  9. hflexgrig commented on Nov 17, 2025

    @hflexgrig

    Adding this to the csproj should work around it:

    --optimize=-register-protocols

    Oh thanks you, but I've found already workaround. (btw above delegate override was throwing exception). Override InsertText worked on release build, only had to create custom event on my customeditor and raise from there.

    public class UIBackwardsTextView : MauiTextView
    {
        private readonly CustomEditor _virtualView;
    
        public UIBackwardsTextView(IEditor virtualView)
        {
            _virtualView = virtualView as CustomEditor;
        }
    
        public override void InsertText(string text)
        {
            base.InsertText(text);
            _virtualView.RaiseCustomText(text);
        }
    }
    
  10. added 3 commits that reference this issue on Nov 17, 2025
    e945091
    0fc104f
    ddee8d3
  11. added 2 commits that reference this issue on Nov 18, 2025
    ec58986
    8899c27
  12. added a commit that references this issue on Nov 19, 2025
    ee0a2be
  13. nvgogh commented on Dec 3, 2025

    @nvgogh

    Adding this to the csproj should work around it:

    --optimize=-register-protocols

    Perfect. Thank you very much. This also solved other issues I had on the same page (like scroll not working)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugregression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions