![](/img/trans.png)
[英]UWP, my app crashes for the image path when built , but when I run it on the debugger it works fine
[英]iOS app crashes when I click on my UIButton
這是我試圖用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.
=================================================================
我被困住了,不知道怎么繼續?
此外, 這是一個顯示錯誤的視頻 (請選擇720p版本)。
這是解決方案,拉鏈 。
從xCode的角度來看,我認為IBOutlet導致應用程序崩潰。 僅僅因為IBOutlets用於狀態而不是用於調用方法。 在這種情況下,您應該將按鈕連接到IBAction:
- (IBAction)Google:(id)sender;
最終將致電:
Google.TouchUpInside += (sender, e) =>
{
xxx++;
};
另請注意,在現代objective-c中,您不需要@synthesize Google = _Google;
這將自動發生。
happy x(amarin)編碼。
你為一個簡單的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不需要任何這個
要打個招呼世界,只需要這個
@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;
當您單擊該按鈕時,編譯器可能不知道您在說什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.