加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 当我点击我的UIButton时iOS应用程序崩溃 – 无法找出原因

发布时间:2020-12-14 18:00:37 所属栏目:百科 来源:网络整理
导读:摘要 这是我试图用Xamarin制作的第一个应用程序.我正在学习Hello World,iPhone的例子.当我点击我的按钮时,应用程序崩溃,我无法弄清楚原因. 细节 我有一个简单的UIViewController和一个UIButton.我创建了一个插座,所以当我点击按钮时,我会做一些事情. 当我连
摘要
这是我试图用Xamarin制作的第一个应用程序.我正在学习Hello World,iPhone的例子.当我点击我的按钮时,应用程序崩溃,我无法弄清楚原因.

细节
我有一个简单的UIViewController和一个UIButton.我创建了一个插座,所以当我点击按钮时,我会做一些事情.

当我连接按钮的TouchUpInside事件时,当我点击按钮时应用程序崩溃.当我删除有线连接事件(但插座仍然存在)时,单击按钮时应用程序不会崩溃. (当然,没有任何事情发生,因为没有任何连线).

杀了我的是我不知道出了什么问题并且使用了调试信息,我无法弄明白!我一直在做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) <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有效.

有什么建议吗?

解决方法

从xCode的角度来看,我认为IBOutlet导致应用程序崩溃.仅仅因为IBOutlets用于状态而不是用于调用方法.在这种情况下,您应该将按钮连接到IBAction:

- (IBAction)Google:(id)sender;

最终将致电:

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

另请注意,在现代objective-c中,您不需要@synthesize Google = _Google;这将自动发生.

happy x(amarin)编码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读