将uigesturerecognzer数据传递给父控制器

时间:2013-05-02 20:39:13

标签: iphone ios uiviewcontroller uigesturerecognizer

使用此方法有一个主视图控制器

- (void)revealGesture:(UIPanGestureRecognizer *)recognizer{ 
}

当我使用滑动向子视图控制器发送消息时,它可以工作:

UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];

我想从子viewController中传递消息,所以我可以先做一些内务管理

    UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(revealGesture:)];
    [self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];

- (void)revealGesture:(UIPanGestureRecognizer *)recognizer
{
    [displaySearch resignFirstResponder];
    RevealController *revealController = [self.navigationController.parentViewController isKindOfClass:[RevealController class]] ? (RevealController *)self.navigationController.parentViewController : nil;

    NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys: recognizer, @"recognizer", nil];

    [revealController performSelector:@selector(revealGesture:) withObject:data];
}

是的,我正在尝试做的就是在继续使用一些可以正常工作的代码之前关闭键盘,如果我只是直接定位'self.navigationController.parentViewController'

如何在NSDictionary中添加(UIPanGestureRecognizer *)识别器?

我的代码崩溃了

-[__NSCFDictionary state]: unrecognized selector sent to instance 0x8619860
2013-05-02 21:12:05.752 PwC UK[57884:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary state]: unrecognized selector sent to instance 0x8619860'

编辑建议的解决方案有效但键盘没有响应,需要将线路变为

[self searchBarCancelButtonClicked:searchBar];

其中searchBar是UISearchBar的实例

1 个答案:

答案 0 :(得分:0)

看起来revealGesture期待UIPanGestureRecognizer作为其参数,但是你传递的是NSDictionary。尝试直接传递手势识别器。

[revealController performSelector:@selector(revealGesture:) withObject: recognizer];