Pur*_*ome 5 .net c# xcode objective-c xamarin
总结
这是我试图用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
Run Code Online (Sandbox Code Playgroud)
.m文件
#import "AuthenticationViewController.h"
@implementation AuthenticationViewController
@synthesize Google = _Google;
@end
Run Code Online (Sandbox Code Playgroud)
设计师档案
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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我的
.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++;
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
哦 - 和金钱射击......(缺乏)崩溃转储/堆栈跟踪
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.
=================================================================
Run Code Online (Sandbox Code Playgroud)
我被困住了,不知道怎么继续?我已经花了好几个小时尝试各种各样的东西来实现这个目标.
此外,这是一个显示错误的视频(请选择720p版本).
这是解决方案,拉上拉链.
我会感激任何帮助 - >而不是说:这里是固定的.但是......你没有做到这一点......你需要做那些事情,所以xxxx有效.
有什么建议吗?
从xCode的角度来看,我认为IBOutlet导致应用程序崩溃.仅仅因为IBOutlets用于状态而不是用于调用方法.在这种情况下,您应该将按钮连接到IBAction:
- (IBAction)Google:(id)sender;
Run Code Online (Sandbox Code Playgroud)
最终将致电:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
Run Code Online (Sandbox Code Playgroud)
另外,请注意,在现代objective-c中,您不需要@synthesize Google = _Google;
自动生成.
happy x(amarin)编码.
归档时间: |
|
查看次数: |
898 次 |
最近记录: |