2013-10-28 24 views
5

Tóm tắt
Đây là ứng dụng đầu tiên của tôi mà tôi đang cố gắng thực hiện với Xamarin. Tôi đang học từ ví dụ Hello World, iPhone. Khi tôi nhấp vào nút của tôi, ứng dụng bị treo và tôi không thể hiểu tại sao.Ứng dụng iOS bị treo khi tôi nhấp vào UIButton của tôi - không thể tìm ra lý do tại sao?

Chi tiết
Tôi đã có một đơn giản UIViewController với một đơn UIButton. Tôi đã tạo ra một cửa hàng vì vậy khi tôi bấm vào nút, tôi làm điều gì đó.

Khi tôi kết nối nút của TouchUpInside event của nút, ứng dụng gặp sự cố khi tôi nhấp vào nút. Khi tôi loại bỏ sự kiện có dây (nhưng ổ cắm vẫn còn tồn tại), ứng dụng không sụp đổ khi tôi nhấp vào nút. (Tất nhiên, không có gì xảy ra bởi vì không có gì được kết nối).

Điều gì giết chết tôi là tôi không biết có gì sai và sử dụng thông tin gỡ lỗi, tôi không thể hiểu được! Tôi đã làm C# code trong nhiều năm nay nhưng chỉ mới bắt đầu ở Xam hơi khác một chút, đặc biệt là khi báo cáo sự cố là .. cũng .. thiếu bất kỳ thông tin nào :(Tôi đoán tôi có thể có một số cài đặt được đánh dấu (ví dụ: không có thông tin debug?)

Vì vậy, đây là một số mã ...

AuthenticationViewController
tập tin .h

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 


@interface AuthenticationViewController : UIViewController { 
UIButton *_Google; 
} 

@property (nonatomic, retain) IBOutlet UIButton *Google; 

@end 

.m tập tin

#import "AuthenticationViewController.h" 

@implementation AuthenticationViewController 

@synthesize Google = _Google; 

@end 

nhà thiết kế tập tin

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; 
      } 
     } 
    } 
} 

và cuối cùng, nộp

cs tôi

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 - và bắn tiền ... các (thiếu) dấu vết đổ/ngăn xếp ngăn xếp

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. 
      ================================================================= 

Tôi bị kẹt và không biết cách tiếp tục? Tôi đã dành một số giờ thử nhiều thứ khác nhau để làm việc này.

Hơn nữa, here's a video showing the error (vui lòng chọn phiên bản 720p).

và đây là số solution, zipped up.

Tôi sẽ đánh giá cao bất kỳ trợ giúp nào -> và không nói: tại đây, đã được khắc phục. nhưng .. bạn không làm được điều này và điều đó .. và bạn cần phải làm những việc đó để xxxx hoạt động.

Bất kỳ đề xuất nào, vui lòng?

+0

Sự cố có xảy ra khi bạn chạy ứng dụng mà không gỡ lỗi không? –

+0

Có. nó cũng xảy ra. –

Trả lời

5

Nhìn vào điều này từ một điểm xCode, tôi nghĩ rằng IBOutlet đang khiến bạn gặp sự cố. Đơn giản chỉ vì IBOutlets được sử dụng cho nhà nước hơn là cho các phương pháp gọi.Trong trường hợp này, bạn nên dây vào nút để một IBAction:

- (IBAction)Google:(id)sender; 

mà cuối cùng sẽ gọi:

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

Ngoài ra, lưu ý rằng trong hiện đại Objective-C bạn không cần @synthesize Google = _Google; rằng sẽ xảy ra tự động.

hạnh phúc x (amarin) Mã hóa.

1

bạn viết rất nhiều mã cho một thế giới hello đơn giản

đây là những gì bạn không cần

@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. 
     ================================================================= 

Vì vậy, nếu bạn thực hiện một thế giới hello với một nút Không cần bất kỳ này

Để thực hiện một thế giới hello chỉ cần

@interface ViewController() 


@property (nonatomic, strong) UILabel *myLabel; 



@implementation ViewController 

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

Xóa mã không cần thiết luôn tốt. Nhưng có lẽ người hỏi cần một phần của nó và điều này gây ra vụ tai nạn. Bất kỳ ý tưởng hoặc nhận xét về những gì có thể đã gây ra sự cố? – Trilarion

1

T này anh ấy nói với chúng tôi có lẽ chúng tôi đang mất liên quan đến một cái gì đó. Tôi biết ai đó đã nói để kích hoạt zombie, nhưng điều này có thể không phải là một tùy chọn với trình bao bọc/trình biên dịch của bạn.

mono-rt: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff> 

Hãy thử thay thế:

@interface AuthenticationViewController : UIViewController { 
    UIButton *_Google; 
} 

@property (nonatomic, retain) IBOutlet UIButton *Google; 

Với chỉ:

@interface AuthenticationViewController : UIViewController 
@property (nonatomic, retain) IBOutlet UIButton *Google; 

Có lẽ trình biên dịch không biết những gì bạn đang nói về khi bạn nhấp vào nút đó.

Các vấn đề liên quan