2013-10-28 75 views
5

摘要
這是我的第一個應用程序,我試圖用Xamarin。我正在從Hello World, iPhone的例子中學習。當我點擊我的按鈕時,應用程序崩潰,我無法弄清楚爲什麼。當我點擊我的UIButton時,iOS應用程序崩潰 - 找不到爲什麼?

詳細
我有一個簡單的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版本)。

這裏是solution, zipped up

我將不勝感激任何幫助 - >而不是說:在這裏,它是固定的。但是..你沒有做到這一點,並且你需要做這些事情,所以xxxx的作品。

有什麼建議嗎?

+0

在沒有調試的情況下運行應用程序時會發生崩潰嗎? –

+0

是的。它也確實發生。 –

回答

5

從xCode的角度來看,我認爲IBOutlet會導致您的應用程序崩潰。只是因爲IBOutlets用於狀態而不是調用方法。在這種情況下,你應該連線按鈕的IBAction爲:

- (IBAction)Google:(id)sender; 

這將最終致電:

Google.TouchUpInside += (sender, e) => 
      { 
       xxx++; 
      }; 

另外,還要注意在現代的Objective-C,你不需要@synthesize Google = _Google;會發生自動。

happy x(amarin)編碼。

1

你寫很多代碼的簡單的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. 
     ================================================================= 

所以,如果你讓一個Hello World一個按鈕,無需任何這

爲了使一個Hello World只需要這個

@interface ViewController() 


@property (nonatomic, strong) UILabel *myLabel; 



@implementation ViewController 

- (IBAction)myButton:(id)sender 
{ 
    _myLabel.Text = @"Hello World "; 
} 
@end 
+2

刪除不必要的代碼總是很好。但也許提問者需要一些,這導致了崩潰。任何關於可能導致崩潰的想法或意見? – Trilarion

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; 

也許編譯器不知道你在說什麼時候你點擊那個按鈕是什麼。

相關問題