0

几年后,我再次尝试使用 XCode 为 iOS 编写一些小应用程序。

我的 MainViewController 在 vi​​ewdidload 中包含这些行:

UIStoryboard* overviewStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *overviewController = [overviewStoryboard instantiateViewControllerWithIdentifier:@"Overview"];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:overviewController];

...

[self addChildViewController:nav];
[self.view addSubview:nav.view];
[nav didMoveToParentViewController:self];

概览后面的控制器包含视图中的整个手势识别确实加载了:

财产

@property (nonatomic, strong) UISwipeGestureRecognizer *swipeGestureUpDown;

viewdidload:

self.tableView.dataSource = self;
self.tableView.delegate = self;

// gesture recognizer top
self.swipeGestureUpDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen)];
self.swipeGestureUpDown.numberOfTouchesRequired = 1;
self.swipeGestureUpDown.direction = (UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown);

[self.view addGestureRecognizer:self.swipeGestureUpDown];

并且 swipedScreen 只有一个 nslog:

- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture
{
    NSLog(@"somewhere");
}

概览控制器包含一个带有自定义单元格的 tableView。主控制器将此概览控制器作为根控制器传递给导航,如果向上滑动,导航应该是 slideUp,如果向下滑动,则应该是 slideIn。如您在上面看到的,主控制器正在调用带有根控制器的导航控制器。

什么都没有发生,没有识别手势,并且在某些尝试中它会因此消息而崩溃

unrecognized selector sent to instance

有人现在该怎么办?

4

1 回答 1

0

问题的答案出现在评论中。只是在这里巩固它。有几个问题。
第一的:

self.swipeGestureUpDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen)];

@selector(swipedScreen)丢失最后swipedScreen使其无法识别,因为函数的定义是- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture

Second:

self.swipeGestureUpDown.direction = (UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown);

具有两个滑动方向的单一手势识别器不起作用。有关详细信息,请参阅。您需要为每个方向配备一个专用的手势识别器。

第三:

最重要的是尝试添加向上和向下方向滑动,UITableView只要启用滚动,它就不起作用,UITableView因为它有自己的默认操作来处理这些滑动,从而防止手动处理。
但是,如果表格中的内容非常有限并且不需要滚动,则可以将其 设置scrollEnabled为停止使用手势并将手势向上转发到响应者链。请参阅此处的说明。(继承自。)falseUITableViewscrollEnabledUITableViewUIScrollView

于 2013-06-19T01:12:00.230 回答