0

这个方法有一个主视图控制器

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

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

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

我想从子视图控制器中传递消息,这样我就可以先做一些家务

    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',这些代码可以正常工作

如何将 (UIPanGestureRecognizer *)recognizer 添加到 NSDictionary?

我的代码崩溃了

-[__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 的实例

4

1 回答 1

0

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

[revealController performSelector:@selector(revealGesture:) withObject: recognizer];
于 2013-05-02T20:47:23.123 回答