摘要
这是我第一个用 Xamarin 制作的应用程序。我正在学习Hello World, iPhone
示例。当我点击我的按钮时,应用程序崩溃,我无法找出原因。
详情
我有一个简单UIViewController
只有一个UIButton
。我创建了一个插座,所以当我点击按钮时,我会做一些事情。
当我按下按钮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.
=================================================================
我被困住了,不知道怎么继续?我已经花了好几个小时尝试各种各样的东西来实现这个目标。
此外,here's a video showing the error(请选择720p版本)。
我将不胜感激任何帮助 - &gt;而不是说:这里是固定的。但是......你没有做到这一点......你需要做那些事情,所以xxxx可以工作。
有什么建议吗?
答案 0 :(得分:5)
从xCode的角度来看,我认为IBOutlet导致应用程序崩溃。仅仅因为IBOutlets用于状态而不是用于调用方法。在这种情况下,您应该将按钮连接到IBAction:
- (IBAction)Google:(id)sender;
最终会调用:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
另请注意,在现代objective-c中,您不需要@synthesize Google = _Google;
自动发生。
happy x(amarin)Coding。
答案 1 :(得分:1)
你为一个简单的hello世界写了很多代码
这是你不需要的东西
@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,不需要任何这个
制作一个hello世界只需要这个
@interface ViewController ()
@property (nonatomic, strong) UILabel *myLabel;
@implementation ViewController
- (IBAction)myButton:(id)sender
{
_myLabel.Text = @"Hello World ";
}
@end
答案 2 :(得分: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;
也许编辑器在您点击该按钮时并不知道您正在谈论的内容。