6

概括

这是我尝试使用Xamarin制作的第一个应用程序。我正在从Hello World, iPhone示例中学习。当我点击我的按钮时,应用程序崩溃了,我不知道为什么。

细节

我有一个简单UIViewControllerUIButton. 我已经创建了一个插座,所以当我点击按钮时,我会做一些事情。

当我连接按钮TouchUpInside event时,单击按钮时应用程序崩溃。当我删除连接事件(但插座仍然存在)时,单击按钮时应用程序不会崩溃。(当然,没有任何事情发生,因为没有任何东西连接起来)。

令我沮丧的是,我不知道出了什么问题,使用调试信息,我无法弄清楚!多年来我一直在编写 C# 代码,但刚开始使用 Xam 有点不同,尤其是当崩溃报告缺少任何信息时。我猜我可能会勾选一些设置(例如,没有调试信息?)

所以这里有一些代码......

AuthenticationViewController
.h 文件

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>


@interface AuthenticationViewController : UIViewController {
UIButton *_Google;
}

@property (nonatomic, retain) IBOutlet UIButton *Google;

@end

.m 文件

#import "AuthenticationViewController.h"

@implementation AuthenticationViewController

@synthesize Google = _Google;

@end

设计器文件

using MonoTouch.Foundation;
using System.CodeDom.Compiler;

namespace Foo.Client.iPhone
{

    [Register ("AuthenticationViewController")]
    partial class AuthenticationViewController
    {
        [Outlet]
        MonoTouch.UIKit.UIButton Google { get; set; }

        void ReleaseDesignerOutlets ()
        {
            if (Google != null) {
                Google.Dispose ();
                Google = null;
            }
        }
    }
}

最后,我的

.cs 文件

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Foo.Client.iPhone
{
    public partial class AuthenticationViewController : UIViewController
    {
        public int xxx = 0;
        public event EventHandler OnAuthenticationCompleted;

        public AuthenticationViewController() 
            : base ("AuthenticationViewController", null)
        {
        }

        public override void DidReceiveMemoryWarning()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.
        }

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

            Google.TouchUpInside += (sender, e) => 
            {
                xxx++;
            };
        }
    }
}

这是(缺少的)崩溃转储/堆栈跟踪

2013-10-25 21:37:13.785 FooClientiPhone[8852:1403] MonoTouch: Socket error while connecting to MonoDevelop on 127.0.0.1:10000: Connection refused
mono-rt: Stacktrace:

mono-rt:   at <unknown> <0xffffffff>

mono-rt:   at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>

mono-rt:   at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38

mono-rt:   at Foo.Client.iPhone.Application.Main (string[]) [0x00008] in /Users/PureKrome/Documents/Mac Projects/Foo iOS Client/Code/Foo.Client.iPhone/Main.cs:16

mono-rt:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

mono-rt: 
    Native stacktrace:

 mono-rt: 
    =================================================================
    Got a SIGSEGV while executing native code. This usually indicates
        a fatal error in the mono runtime or one of the native libraries 
            used by your application.
            =================================================================

我被卡住了,不知道如何继续?

此外,这是一个显示错误的视频(请选择 720p 版本)。

这是解决方案,拉上拉链

4

3 回答 3

5

从 xCode 的角度来看,我认为 IBOutlet 导致您的应用程序崩溃。仅仅是因为 IBOutlets 用于状态而不是用于调用方法。在这种情况下,您应该将按钮连接到 IBAction:

- (IBAction)Google:(id)sender; 

最终将调用:

Google.TouchUpInside += (sender, e) => 
            {
                xxx++;
            };

另外,请注意,在现代objective-c 中,您不需要@synthesize Google = _Google;它会自动发生。

快乐 x(amarin) 编码。

于 2014-09-12T04:33:34.363 回答
1

这告诉我们也许我们正在失去对某些东西的引用。我知道有人已经说过要启用僵尸,但这可能不是您的包装器/编译器的选项。

mono-rt:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

尝试更换:

@interface AuthenticationViewController : UIViewController {
    UIButton *_Google; 
}

@property (nonatomic, retain) IBOutlet UIButton *Google;

只需:

@interface AuthenticationViewController : UIViewController 
@property (nonatomic, retain) IBOutlet UIButton *Google;

当您单击该按钮时,编译器可能不知道您在说什么。

于 2014-09-16T15:09:12.797 回答
1

你为一个简单的 hello world 写了很多代码

这是你不需要的

@property (nonatomic, retain) IBOutlet UIButton *Google;
@synthesize Google = _Google;

using  MonoTouch . Foundation ; 
using  System . CodeDom . Compiler ; 

namespace  Foo . Client . iPhone
{ 

[ Register  ( "AuthenticationViewController" )] 
partial  class  AuthenticationViewController 
{ 
    [ Outlet ] 
    MonoTouch . UIKit . UIButton  Google  {  get ;  set ;  } 

    void  ReleaseDesignerOutlets  () 
    { 
        if  ( Google  !=  null )  { 
            Google . Dispose  (); 
            Google  =  null ; 
        } 
       } 
    } 
   }
  using System;
  using System.Drawing;
  using MonoTouch.Foundation;
  using MonoTouch.UIKit;

  namespace Foo.Client.iPhone
 {
 public partial class AuthenticationViewController : UIViewController
 {
    public int xxx = 0;
    public event EventHandler OnAuthenticationCompleted;

    public AuthenticationViewController() 
        : base ("AuthenticationViewController", null)
    {
    }

    public override void DidReceiveMemoryWarning()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.
    }

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

        Google.TouchUpInside += (sender, e) => 
        {
            xxx++;
        };
    }
   }
   } 2013-10-25 21:37:13.785 FooClientiPhone[8852:1403] MonoTouch: Socket error while           connecting to MonoDevelop on 127.0.0.1:10000: Connection refused
    mono-rt: Stacktrace:

   mono-rt:   at <unknown> <0xffffffff>

  mono-rt:   at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain         (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>

  mono-rt:   at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38

  mono-rt:   at Foo.Client.iPhone.Application.Main (string[]) [0x00008] in /Users/PureKrome/Documents/Mac Projects/Foo iOS Client/Code/Foo.Client.iPhone/Main.cs:16

mono-rt:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object          (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

   mono-rt: 
   Native stacktrace:
  mono-rt: 
   =================================================================
    Got a SIGSEGV while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
        used by your application.
        =================================================================

所以如果你用一个按钮创造一个你好世界 不需要这些

打造一个 hello world 只需要这个

@interface ViewController ()


@property (nonatomic, strong) UILabel *myLabel;



@implementation ViewController

- (IBAction)myButton:(id)sender 
{ 
  _myLabel.Text = @"Hello World ";
}
@end
于 2014-09-16T12:37:15.867 回答