C# 当我点击我的UI按钮时,iOS应用程序崩溃 总结
这是我试图用Xamarin制作的第一个应用程序。我正在学习Hello World,iPhone的例子。当我点击我的按钮时,应用程序崩溃了,我不知道为什么 细节 我有一个简单的UIViewController和一个UIButton。我已经创建了一个出口,所以当我点击按钮时,我会做一些事情 当我连接按钮的TouchUpInside事件时,当我单击按钮时,应用程序崩溃。当我删除有线事件但插座仍然存在时,当我单击按钮时,应用程序不会崩溃。当然,没有任何事情发生,因为没有任何事情是有关联的 让我沮丧的是,我不知道什么是错误的,使用调试信息,我无法找出它!我已经做了很多年的C代码了,但是仅仅从Xam开始就有点不同了,特别是当崩溃报告缺少任何信息的时候。我猜我可能勾选了一些设置,例如没有调试信息 所以这里有一些代码 AuthenticationViewController .h文件 设计器文件 最后,我的 .cs文件 下面是缺少的崩溃转储/堆栈跟踪C# 当我点击我的UI按钮时,iOS应用程序崩溃 总结,c#,.net,objective-c,xcode,xamarin,C#,.net,Objective C,Xcode,Xamarin,这是我试图用Xamarin制作的第一个应用程序。我正在学习Hello World,iPhone的例子。当我点击我的按钮时,应用程序崩溃了,我不知道为什么 细节 我有一个简单的UIViewController和一个UIButton。我已经创建了一个出口,所以当我点击按钮时,我会做一些事情 当我连接按钮的TouchUpInside事件时,当我单击按钮时,应用程序崩溃。当我删除有线事件但插座仍然存在时,当我单击按钮时,应用程序不会崩溃。当然,没有任何事情发生,因为没有任何事情是有关联的 让我沮丧的是,
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版本
以下是从xCode的角度来看的。我认为IBOutlet正在导致应用程序崩溃。这仅仅是因为IBOutlets用于状态,而不是用于调用方法。在这种情况下,应将按钮连接到iAction:
- (IBAction)Google:(id)sender;
这最终将要求:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
另外,请注意,在现代objective-c中,您不需要@synthesis Google=\u Google;这将自动发生
快乐的Xamarin编码。你为一个简单的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.
=================================================================
这告诉我们,也许我们正在失去一些参考。我知道有人已经说过要启用僵尸,但这可能不是包装器/编译器的选项
mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
只要:
@interface AuthenticationViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIButton *Google;
当您单击该按钮时,编译器可能不知道您在说什么。在未调试的情况下运行应用程序时是否会发生崩溃?是的。删除不必要的代码总是好的。但也许询问者需要一些,这导致了坠机。有什么想法或评论可能导致了这次坠机?
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
@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.
=================================================================
@interface ViewController ()
@property (nonatomic, strong) UILabel *myLabel;
@implementation ViewController
- (IBAction)myButton:(id)sender
{
_myLabel.Text = @"Hello World ";
}
@end
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;