wwdc14yh / HyPopMenuView

模仿新浪微博弹出菜单
726 stars 186 forks source link

IOS8.0 swift 点击menu button后 delegate没有被调用 #8

Closed yujia917 closed 7 years ago

yujia917 commented 8 years ago

public func popMenuView(popMenuView: HyPopMenuView!, didSelectItemAtIndex index: UInt) { }

点击menu button之后,上面的delegate没被调用, 不知道什么问题。Debug的时候,显示下面方法里的这个if条件不满足: if ([weakView.delegate respondsToSelector:@selector(popMenuView:didSelectItemAtIndex:)])

Shin1122 commented 8 years ago

我测试的时候也遇到同样的问题,查了一源代码,回调的时候因为调用了[weakView currentViewController] 这个方法,而currentViewController方法返回的的viewController 并不是你调用popMenu的所在的页面的那个controller。而是viewController(就是rootViewController),代理执行方法也只能在viewController里调用。测试了一下午才发现这个问题。

同样的,else { NSLog(@"不在同一个控制器"); } 源码这一段,我感觉可能是套错括号了。因为在你调不到点击事件代理方法的时候,就是viewcontroller错误的问题。所以这层括号应该是上一个if的else。这是我自己的猜测,不知道对不对呢。。。。

yujia917 commented 8 years ago

popMenu是通过tabBarController打开的,[weakView currentViewController] 返回的是当前所在的viewController,而不是tabBarController. 假如tabBarController有五个viewController, 同样的delegate要在每个controller里都写一遍?

这个楼主有什么好建议或是修改计划?

Shin1122 commented 7 years ago

我的做法:在viewController里遵循PopMenu的协议,在viewcontroller里执行代理方法。只能临时解决。

wwdc14yh commented 7 years ago

@yujia917 @Shin1122 代理不执行问题已经修复 原因是因为PopMenuView是单利模式,因此在多个ViewController里遵循delegate都会执行delegate里的方法。