【问题标题】:UITapGestureRecognizer Crashes on iOS SimulatoriOS 模拟器上的 UITapGestureRecognizer 崩溃
【发布时间】:2014-11-04 10:09:07
【问题描述】:

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

这是我的手势:

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

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

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

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() 方法。 有很多方法可以使某些东西可点击,但为什么我不能只使用上面的这个呢??

【问题讨论】:

  • 您是否尝试添加使用以选择器为参数的构造函数创建的 Tapgesture?
  • 是的,我试过了,但不幸的是,这并不能解决我的问题,因为我需要在创建手势的同一上下文中使用具有代表的手势。

标签: ios xamarin.ios xamarin uitapgesturerecognizer


【解决方案1】:

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

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) 的第一个参数指向包含具有指定导出属性的方法定义的对象,因此如果您要在视图中定义选择器和方法,则 NSObject 目标将是您视图的引用,如果您要调用的方法存在单元格中的示例,您的单元格引用将成为目标。

编辑

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

在您的 UITableSource 中声明事件,例如
public event EventHandler&lt;DataBaseModels.SavedActions&gt; OnActionSelected;
然后在 getCell 中将轻击手势分配给您的视图和内部方法,您将拥有引用发件人对象,将其转换为 UIView 并保留标签以识别相应的记录

【讨论】:

  • 我现在试过了,但我在 StringElement (MonoTouch.Dialog) 内部,显然我不能将它用作目标 (NSObject)。但我真的很确定我过去这样做过......
  • 好的,这工作(在模拟器中)但不切实际,我必须传递对我的单元格的引用,并且我必须找到一种方法来确定哪个被窃听...在我的设备上我得到了无法识别的选择器异常。手势的 NSAction 构造有什么问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-27
  • 2011-12-09
  • 2013-09-27
  • 2012-06-28
  • 1970-01-01
  • 2013-01-25
  • 1970-01-01
相关资源
最近更新 更多