ios - UITapGestureRecognizer 在 iOS 模拟器上崩溃

标签 ios xamarin.ios xamarin uitapgesturerecognizer

当我尝试使用 UITapGestureRecognizer 时,我的 iOS 模拟器崩溃了。

这是我的手势:

UITapGestureRecognizer tap = new UITapGestureRecognizer (new NSAction(delegate {
  if(SettingsTapped != null){
     SettingsTapped(this, EventArgs.Empty);
  }
}));

我正在将此 Gesture 添加到 UIView,然后将此 View 添加到 UITableViewCell。 应用程序在触摸 View 后崩溃(每次),没有显示异常。

她是模拟器日志文件的输出:

Nov  4 10:49:47 administorsmini xXxXx[11073]: assertion failed: 13E28 12B411: libsystem_sim_trace.dylib + 19982 [BEE53863-0DEC-33B1-BFFB-8F7AE595CC73]: 0x4
Nov  4 10:49:49 administorsmini xXxXx[11073]: Stacktrace:
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at <unknown> <0xffffffff>
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x000a6, 0xffffffff>
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at MonoTouch.UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at xXxXx.Application.Main (string[]) [0x00008] in /Users/Norman/Desktop/xXxXx/xXxXx/Main.cs:17
Nov  4 10:49:49 administorsmini xXxXx[11073]:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Nov  4 10:49:49 administorsmini xXxXx[11073]: 
Native stacktrace:
Nov  4 10:49:49 administorsmini xXxXx[11073]: 
=================================================================
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.
=================================================================
Nov  4 10:49:49 administorsmini com.apple.CoreSimulator.SimDevice.27B5D497-B641-4BCA-8FA0-EF9E28E07143.launchd_sim[10951] (UIKitApplication:com.your-company.xXxXx[0x7041][11073]): Service exited due to signal: Abort trap: 6
Nov  4 10:49:49 administorsmini SpringBoard[10962]: Application 'UIKitApplication:com.your-company.xXxXx[0x7041]' crashed.
Nov  4 10:49:49 administorsmini assertiond[10966]: notify_suspend_pid() failed with error 7
Nov  4 10:49:49 administorsmini assertiond[10966]: assertion failed: 13E28 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1

我现在可以做什么? 我不想在设备上开发...

编辑

我最终覆盖了 UIView 并使用了它的 TouchesBegan() 方法。 有很多方法可以使某些内容可点击,但为什么我不能只使用上面的这个方法呢??

最佳答案

这是我在我的应用程序中使用的一些代码:

private void addTapGesture()
{
   imgLogo.UserInteractionEnabled = true;
   var tapGesture = new UITapGestureRecognizer(this, new Selector("ResendTrigger:"));
   tapGesture.NumberOfTapsRequired = 5;
   imgLogo.AddGestureRecognizer(tapGesture);           
}

[Export("ResendTrigger:")]
public void ResendTrigger(UIGestureRecognizer sender)
{
    System.Diagnostics.Debug.WriteLine("Triggered");}
}

构造函数的第一个参数 (this) 指向包含具有指定 Export 属性的方法定义的对象,因此如果您将在 View 中定义选择器和方法,如果您要调用的方法存在,NSObject 目标将是您 View 的引用单元格中的示例您的单元格引用将是目标。

编辑

根据评论,我假设您可能正在使用 UITableViewSource 。我认为您的情况与我的相似,因此请尝试以下方法:

在您的 UITableSource 中声明事件,例如
public event EventHandler<DataBaseModels.SavedActions> OnActionSelected;
然后在 getCell 中将点击手势分配给您的 View 和内部方法,您将引用发送者对象,将其转换为 UIView 并保留标签以识别相应的记录

关于ios - UITapGestureRecognizer 在 iOS 模拟器上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26732486/

相关文章:

ios - 检查 iOS 6 中是否安装了 Google map 应用程序

ios - 使用 Objective-C 属性 getter 实现 Swift 协议(protocol)

ios - 如何使用 Swift 打开谷歌地图以显示路线

c# - Monotouch UITableView 或 MonoTouch.Dialog

Xamarin.Forms Shell - 除非在 <Tab> 内,否则无法使用 ShellContent?

c# - 处理大量类 : Can I nest C# files in folders arbitrarily?

ios - 我想快速将 UIImage 与字符串进行编码和解码,以获取 AEXML 中的值

c# - 如何在 xamarin ios 中创建类别?

ios - Monotouch.Dialog 从数据库生成并保留值

xamarin - Windows运行时元数据在SDK中无效-ITIL00005