Xamarin.ios 上次更新后NavigationItem RightBarButtonim出现问题

Xamarin.ios 上次更新后NavigationItem RightBarButtonim出现问题,xamarin.ios,rightbarbuttonitem,navigationitem,Xamarin.ios,Rightbarbuttonitem,Navigationitem,在上次更新(4.0.0)之后,我遇到了一个问题,我想知道这是一个bug,是否有修复程序 从下面的代码中可以看到,我正在创建一个NavigationItem.RightBarButtonItem,并向TouchUpInside事件添加一个委托。按钮是创建的,但当触摸发生时,应用程序会可怕地死掉(见下文)。在此更新之前,代码运行良好 有人知道吗?Monotouch团队,你意识到这个问题了吗?也许我只是编码不正确,以前工作过,但新的更新证明我编码不正确 问候, 丹尼 密码 错误 堆栈跟踪: 0 S

在上次更新(4.0.0)之后,我遇到了一个问题,我想知道这是一个bug,是否有修复程序

从下面的代码中可以看到,我正在创建一个NavigationItem.RightBarButtonItem,并向TouchUpInside事件添加一个委托。按钮是创建的,但当触摸发生时,应用程序会可怕地死掉(见下文)。在此更新之前,代码运行良好

有人知道吗?Monotouch团队,你意识到这个问题了吗?也许我只是编码不正确,以前工作过,但新的更新证明我编码不正确

问候,

丹尼

密码 错误 堆栈跟踪:

0   SmartPhoneSolution1                 0x000d0db5 mono_handle_native_sigsegv + 343
1   SmartPhoneSolution1                 0x0000f80c mono_sigsegv_signal_handler + 322
2   libSystem.B.dylib                   0x996fb45b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   UIKit                               0x01b92de0 -[UIControl sendAction:to:forEvent:] + 67
5   UIKit                               0x01b95262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
6   UIKit                               0x01b93e0f -[UIControl touchesEnded:withEvent:] + 458
7   UIKit                               0x01b2b3d0 -[UIWindow _sendTouchesForEvent:] + 567
8   UIKit                               0x01b0ccb4 -[UIApplication sendEvent:] + 447
9   UIKit                               0x01b119bf _UIApplicationHandleEvent + 7672
10  GraphicsServices                    0x05768822 PurpleEventCallback + 1550
11  CoreFoundation                      0x00debff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12  CoreFoundation                      0x00d4c807 __CFRunLoopDoSource1 + 215
13  CoreFoundation                      0x00d49a93 __CFRunLoopRun + 979
14  CoreFoundation                      0x00d49350 CFRunLoopRunSpecific + 208
15  CoreFoundation                      0x00d49271 CFRunLoopRunInMode + 97
16  GraphicsServices                    0x0576700c GSEventRunModal + 217
17  GraphicsServices                    0x057670d1 GSEventRun + 115
18  UIKit                               0x01b15af2 UIApplicationMain + 1160
19  ???                                 0x0ba72744 0x0 + 195503940
20  ???                                 0x0ba7267a 0x0 + 195503738
21  ???                                 0x090bfb9e 0x0 + 151780254
22  ???                                 0x090bfaea 0x0 + 151780074
23  ???                                 0x090bfb75 0x0 + 151780213
24  SmartPhoneSolution1                 0x0000f5c7 mono_jit_runtime_invoke + 1332
25  SmartPhoneSolution1                 0x001ed281 mono_runtime_invoke + 137
26  SmartPhoneSolution1                 0x001ef968 mono_runtime_exec_main + 669
27  SmartPhoneSolution1                 0x001eed52 mono_runtime_run_main + 843
28  SmartPhoneSolution1                 0x000a3153 mono_jit_exec + 200
29  SmartPhoneSolution1                 0x002a16b8 main + 4155
30  SmartPhoneSolution1                 0x00002949 _start + 208
31  SmartPhoneSolution1                 0x00002878 start + 40
at(包装器管理为本机)MonoTouch.UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) 在/Users/plasma/Source/iphone/MonoTouch/UIKit/UIApplication.Main(字符串[],字符串,字符串)[0x00038]中 位于/Users/plasma/Source/iphone/MonoTouch/UIKit/UIApplication.Main(字符串[])中的[0x00000] 位于/Users/aprdev/Projects/SmartPhoneSolution/SmartPhoneSolution/Main.cs:15中的SmartPhoneSolution.Application.Main(字符串[])[0x00000] 在(包装器运行时调用)。运行时调用无效对象(对象,intptr,intptr,intptr)

本机堆栈跟踪:

0   SmartPhoneSolution1                 0x000d0db5 mono_handle_native_sigsegv + 343
1   SmartPhoneSolution1                 0x0000f80c mono_sigsegv_signal_handler + 322
2   libSystem.B.dylib                   0x996fb45b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   UIKit                               0x01b92de0 -[UIControl sendAction:to:forEvent:] + 67
5   UIKit                               0x01b95262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
6   UIKit                               0x01b93e0f -[UIControl touchesEnded:withEvent:] + 458
7   UIKit                               0x01b2b3d0 -[UIWindow _sendTouchesForEvent:] + 567
8   UIKit                               0x01b0ccb4 -[UIApplication sendEvent:] + 447
9   UIKit                               0x01b119bf _UIApplicationHandleEvent + 7672
10  GraphicsServices                    0x05768822 PurpleEventCallback + 1550
11  CoreFoundation                      0x00debff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12  CoreFoundation                      0x00d4c807 __CFRunLoopDoSource1 + 215
13  CoreFoundation                      0x00d49a93 __CFRunLoopRun + 979
14  CoreFoundation                      0x00d49350 CFRunLoopRunSpecific + 208
15  CoreFoundation                      0x00d49271 CFRunLoopRunInMode + 97
16  GraphicsServices                    0x0576700c GSEventRunModal + 217
17  GraphicsServices                    0x057670d1 GSEventRun + 115
18  UIKit                               0x01b15af2 UIApplicationMain + 1160
19  ???                                 0x0ba72744 0x0 + 195503940
20  ???                                 0x0ba7267a 0x0 + 195503738
21  ???                                 0x090bfb9e 0x0 + 151780254
22  ???                                 0x090bfaea 0x0 + 151780074
23  ???                                 0x090bfb75 0x0 + 151780213
24  SmartPhoneSolution1                 0x0000f5c7 mono_jit_runtime_invoke + 1332
25  SmartPhoneSolution1                 0x001ed281 mono_runtime_invoke + 137
26  SmartPhoneSolution1                 0x001ef968 mono_runtime_exec_main + 669
27  SmartPhoneSolution1                 0x001eed52 mono_runtime_run_main + 843
28  SmartPhoneSolution1                 0x000a3153 mono_jit_exec + 200
29  SmartPhoneSolution1                 0x002a16b8 main + 4155
30  SmartPhoneSolution1                 0x00002949 _start + 208
31  SmartPhoneSolution1                 0x00002878 start + 40
来自gdb的调试信息:

/tmp/mono gdb命令。WL0ypx:1:源命令文件中出现错误: 无法自行调试

================================================================= 在执行本机代码时收到SIGSEGV。这通常表明 mono运行时或某个本机库中出现致命错误

由您的应用程序使用。 未处理的异常:System.NullReferenceException:对象引用未设置为对象的实例 at(包装器管理为本机)MonoTouch.UIKit.UIApplication:UIApplicationMain(int,string[],intptr,intptr) 在/Users/plasma/Source/iphone/MonoTouch/UIKit/UIApplication.Main中的MonoTouch.UIKit.UIApplication.Main(System.String[]args,System.String principalClassName,System.String delegateClassName)[0x00038] 在/Users/plasma/Source/iphone/MonoTouch/UIKit/UIApplication.Main(System.String[]args)[0x00000]中 在/Users/aprdev/Projects/SmartPhoneSolution/SmartPhoneSolution/Main.cs:15中的SmartPhoneSolution.Application.Main(System.String[]args)[0x00000]中,我上周有一个。看起来MT4在GC中比以前的版本更具攻击性,而我以前能够侥幸逃脱的东西现在正在引发问题


尝试在类级别声明UIButton,而不是在本地定义它的作用域

同样的事情发生在我移植现有Objective-C代码时。此解决方案是确保您的按钮是类的实例成员。此代码运行良好(省略了额外的viewcontroller样板代码):


请参阅MonoTouch文档中的最后一段(“何时保留对对象的引用”):

在tableview中选择单元格时,我遇到了类似的错误。仅在更新到MonoTouch 4Ok之后。简单的修复。确保对象层次结构中至少有一个对象在类范围内。公平地说,Jason已经正确地回答了这个问题,我只是在用有效的代码进行放大。我试着投票支持他的答案,但我在这个账户上还没有足够的声望点。呵呵。。。几乎现在高达11分。。。还需要15人投票。但是谢谢@西奥法尼斯——两年过去了,终于投票给杰森,因为他应得的荣誉!;-)我现在有了必要的名声:)
public partial class HomeViewController : UIViewController
{
    private UIButton _settingsButton;

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        ConfigureNavigationBar();
    }

    private void ConfigureNavigationBar()
    {
        // Add the Settings icon to nav bar

        _settingsButton = UIButton.FromType(UIButtonType.Custom);

        _settingsButton.SetImage(UIImage.FromBundle("Images/settings.png"),
            UIControlState.Normal);

        _settingsButton.SizeToFit();

        _settingsButton.TouchUpInside += (sender, e) =>
            Console.WriteLine("clicked");

        this.NavigationItem.RightBarButtonItem =
            new UIBarButtonItem(_settingsButton);
    }
}