Summary
This is my first app i'm trying to make with Xamarin. I'm learning from the Hello World, iPhone
example. When I click on my button, the app crashes and I can't figure out why.
这是我用Xamarin做的第一个应用。我正在学习Hello World, iPhone的例子。当我点击按钮时,应用程序崩溃了,我不知道为什么。
Details
I've got a simple UIViewController
with a single UIButton
. I've created an outlet so when I click on the button, I do something.
我有一个简单的UIViewController只有一个UIButton。我创建了一个outlet,所以当我点击按钮时,我做了一些事情。
When I wire up the button's TouchUpInside event
, the app crashes when I click on the button. When I remove the wired up event (but the outlet still exists), the app doesn't crash when I click on the button. (Of course, nothing happens because nothing is wired up).
当我将按钮的TouchUpInside事件连接起来时,当我点击按钮时应用程序就会崩溃。当我删除了有线up事件(但outlet仍然存在),当我点击按钮时应用程序不会崩溃。(当然,什么都不会发生,因为没有什么是固定的)。
What kills me is that I have no idea what is wrong and using the debug info, I can't figure it out! I've been doing c# code for years now but just starting in Xam is a bit different, especially when the crash report is .. well.. lacking any info :( I'm guessing I might have some settings ticked off (eg. no debug info?)
我最讨厌的是,我不知道哪里出了问题,使用调试信息,我搞不清楚!我做c#代码已经很多年了,但是从Xam开始就有点不同了,特别是当崩溃报告是。嗯. .缺少任何信息(我猜我可能会有一些设置)。没有调试信息?)
So here's some code...
这里是一些代码…
AuthenticationViewController
.h file
AuthenticationViewController . h文件
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface AuthenticationViewController : UIViewController {
UIButton *_Google;
}
@property (nonatomic, retain) IBOutlet UIButton *Google;
@end
.m file
m文件
#import "AuthenticationViewController.h"
@implementation AuthenticationViewController
@synthesize Google = _Google;
@end
designer file
设计文件
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;
}
}
}
}
and finally, my
最后,我
.cs file
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++;
};
}
}
}
Oh - and the money shot ... the (lacking) crash dump / stack trace
哦,还有钱……(缺少)崩溃转储/堆栈跟踪。
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.
=================================================================
I'm stuck and have no idea how to continue? I've already spent a number of hours trying various things out to get this working.
我被困住了,不知道该怎么继续?我已经花了好几个小时去尝试各种各样的东西来让它工作。
Further more, here's a video showing the error (please select the 720p version).
此外,这里还有一个显示错误的视频(请选择720p版本)。
and here's the solution, zipped up.
这就是解,拉上拉链。
I would appreciate any help -> and not to say: here it is, fixed. but .. you failed to do this and that .. and u need to do those things so xxxx works.
如果有任何帮助,我将不胜感激。但. .你没能做到这一点。你需要做这些事情,所以xxxx可以工作。
Any suggestions, please?
有什么建议吗?
3 个解决方案
#1
5
Looking at this from an xCode point of view I think that the IBOutlet is causing you app to crash. Simply because IBOutlets are used for state rather than for calling methods. In this case, you should wire the button to a IBAction:
从xCode的角度来看,我认为IBOutlet正在导致应用程序崩溃。因为iboutlet是用于状态而不是调用方法的。在这种情况下,您应该将按钮连接到IBAction:
- (IBAction)Google:(id)sender;
which will eventually call:
这最终将调用:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
Also, note that in modern objective-c you don't need @synthesize Google = _Google;
that will happen automatically.
另外,注意在现代objective-c中,不需要@synthesize谷歌= _Google;这将自动发生。
happy x(amarin)Coding.
快乐的x(amarin)编码。
#2
1
This tells us perhaps we're losing reference to something. I know someone's already said to enable zombies, but this may not be an option with your wrapper/compiler.
这告诉我们,我们可能正在失去某些东西。我知道有人已经说过要启用僵尸,但这可能不是你的包装/编译器的选项。
mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Try replacing:
试着更换:
@interface AuthenticationViewController : UIViewController {
UIButton *_Google;
}
@property (nonatomic, retain) IBOutlet UIButton *Google;
With just:
只有:
@interface AuthenticationViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIButton *Google;
Perhaps the compiler doesn't know what you're talking about when you click that button.
也许当你点击那个按钮时,编译器不知道你在说什么。
#3
1
you write a lot of code for a simple hello world
您为一个简单的hello world编写了大量代码
this is what you do NOT need
这是你不需要的
@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.
=================================================================
So if you make a hello world with a button No need any of this
因此,如果你用一个按钮创建一个hello world,不需要任何这些
To make a hello world only needs this
要打造一个“你好”的世界,只需要这个
@interface ViewController ()
@property (nonatomic, strong) UILabel *myLabel;
@implementation ViewController
- (IBAction)myButton:(id)sender
{
_myLabel.Text = @"Hello World ";
}
@end
#1
5
Looking at this from an xCode point of view I think that the IBOutlet is causing you app to crash. Simply because IBOutlets are used for state rather than for calling methods. In this case, you should wire the button to a IBAction:
从xCode的角度来看,我认为IBOutlet正在导致应用程序崩溃。因为iboutlet是用于状态而不是调用方法的。在这种情况下,您应该将按钮连接到IBAction:
- (IBAction)Google:(id)sender;
which will eventually call:
这最终将调用:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
Also, note that in modern objective-c you don't need @synthesize Google = _Google;
that will happen automatically.
另外,注意在现代objective-c中,不需要@synthesize谷歌= _Google;这将自动发生。
happy x(amarin)Coding.
快乐的x(amarin)编码。
#2
1
This tells us perhaps we're losing reference to something. I know someone's already said to enable zombies, but this may not be an option with your wrapper/compiler.
这告诉我们,我们可能正在失去某些东西。我知道有人已经说过要启用僵尸,但这可能不是你的包装/编译器的选项。
mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Try replacing:
试着更换:
@interface AuthenticationViewController : UIViewController {
UIButton *_Google;
}
@property (nonatomic, retain) IBOutlet UIButton *Google;
With just:
只有:
@interface AuthenticationViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIButton *Google;
Perhaps the compiler doesn't know what you're talking about when you click that button.
也许当你点击那个按钮时,编译器不知道你在说什么。
#3
1
you write a lot of code for a simple hello world
您为一个简单的hello world编写了大量代码
this is what you do NOT need
这是你不需要的
@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.
=================================================================
So if you make a hello world with a button No need any of this
因此,如果你用一个按钮创建一个hello world,不需要任何这些
To make a hello world only needs this
要打造一个“你好”的世界,只需要这个
@interface ViewController ()
@property (nonatomic, strong) UILabel *myLabel;
@implementation ViewController
- (IBAction)myButton:(id)sender
{
_myLabel.Text = @"Hello World ";
}
@end