【问题标题】:Call a function of an another class (protocol)调用另一个类(协议)的函数
【发布时间】:2015-10-27 15:20:47
【问题描述】:

我的第一页上有一个滑出式导航面板(菜单)和另一个“菜单”。

滑出菜单:

  • 索引
  • 第 1 页
  • 第 2 页
  • 第 3 页
  • 第 4 页

在索引上:

  • 第 1 页
  • 第 2 页
  • 第 3 页
  • 第 4 页

因此用户可以从索引或通过滑动(或点击图标菜单)访问页面以获取菜单。

但我有一个错误:我从索引转到第 1 页,我点击图标菜单以滑出菜单 我点击索引,我再次从索引转到第 1 页,如果我再次点击这里在图标菜单上,我收到错误:SIGBRT (类似的)

我做了一些断点:

在这条线上:self.delegate?.pushViewControllerInStack!(UIStoryboard.nosOffresViewController(‌​)!)

还有一个函数pushViewControllerInStack

当我进行操作时,我的应用读取了这一行 self.delegate?.pushViewControllerInStack!(UIStoryboard.nosOffresViewController(‌​)!) 但它没有进入函数。

所以我对这个函数的看法是lost the access,但我不知道为什么以及如何解决这个问题。

代码很多,你可以在这里找到一个git仓库:https://github.com/Vkt0r/SlideOutSideBarTest

错误:

2015-10-28 09:00:33.038 Solutis[477:5075] -[Solutis.NosOffresViewController menuNosOffresTapped:]: unrecognized selector sent to instance 0x7ff5caf464e0
2015-10-28 09:00:33.045 Solutis[477:5075] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Solutis.NosOffresViewController menuNosOffresTapped:]: unrecognized selector sent to instance 0x7ff5caf464e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f3b1f65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000111268deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010f3ba58d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010f307f7a ___forwarding___ + 970
    4   CoreFoundation                      0x000000010f307b28 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010fdf31fa -[UIApplication sendAction:to:from:forEvent:] + 92
    6   UIKit                               0x00000001101d5247 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 152
    7   UIKit                               0x000000010fdf31fa -[UIApplication sendAction:to:from:forEvent:] + 92
    8   UIKit                               0x000000010ff57504 -[UIControl sendAction:to:forEvent:] + 67
    9   UIKit                               0x000000010ff577d0 -[UIControl _sendActionsForEvents:withEvent:] + 311
    10  UIKit                               0x000000010ff5794b -[UIControl _sendActionsForEvents:withEvent:] + 690
    11  UIKit                               0x000000010ff56906 -[UIControl touchesEnded:withEvent:] + 601
    12  UIKit                               0x000000010fe5daa3 -[UIWindow _sendTouchesForEvent:] + 835
    13  UIKit                               0x000000010fe5e691 -[UIWindow sendEvent:] + 865
    14  UIKit                               0x000000010fe10752 -[UIApplication sendEvent:] + 263
    15  UIKit                               0x000000010fdebfcc _UIApplicationHandleEventQueue + 6693
    16  CoreFoundation                      0x000000010f2de0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x000000010f2d3fcc __CFRunLoopDoSources0 + 556
    18  CoreFoundation                      0x000000010f2d3483 __CFRunLoopRun + 867
    19  CoreFoundation                      0x000000010f2d2e98 CFRunLoopRunSpecific + 488
    20  GraphicsServices                    0x000000011485bad2 GSEventRunModal + 161
    21  UIKit                               0x000000010fdf1676 UIApplicationMain + 171
    22  Solutis                             0x000000010f1b892d main + 109
    23  libdyld.dylib                       0x0000000111d8092d start + 1
    24  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

【问题讨论】:

  • 你真的应该发布整个错误。 “SIGBRT(类似的东西)”不会帮助任何人解决您的问题。此外,不太可能有人会访问您的 github 存储库并查看您的所有代码并尝试找出错误。我会发布你调用这些操作的代码块(不仅仅是上面的一行)。
  • 当你得到 SIGABRT 时,Xcode 应该显示调试导航器(在 Xcode 窗口的左侧)。选择堆栈跟踪的所有行,复制它们,然后将它们粘贴到您的问题中。
  • @AndrewRobinson 我刚刚发布了错误代码,我认为它没有用,因为我会发布我的应用程序的 80%
  • @robmayoff 我刚刚发布了错误代码

标签: ios swift function protocols


【解决方案1】:

您将操作与栏项目相关联

你评论了它:

因此,当您尝试在该页面打开菜单时,它会崩溃。

【讨论】:

  • 感谢您的回复,如果我不发表评论:应用程序转到此行:delegate?toggleLeftpanel() 但它没有转到功能,它不起作用。
  • 你可以只评论那行而不是方法
  • 是的,但我只是评论它,因为这种方式不起作用所以我正在尝试其他方式,我想在点击时打开滑出导航面板,但应用程序崩溃,我不明白,第一次可以,第二次就不行了
  • 您需要确保从故事板获取代理时它仍然在那里
  • 怎么看?我做了一些测试:第一次图标菜单工作,因为它是功能下的按钮:pushviewcontrollerinstack,但第二次,它是情节提要的图标菜单而不是pushviewcontroller的图标菜单,因为该功能没有执行。 (对不起我的英语)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-14
  • 1970-01-01
  • 2018-11-30
  • 1970-01-01
  • 2020-04-15
  • 2016-03-30
  • 1970-01-01
相关资源
最近更新 更多