预览操作项未被调用(Force Touch 动作)

3
我正在使用以下代码添加力触预览操作... Peek和pop视图效果很好,但是操作不显示...请帮忙检查一下,我的代码由于某些原因没有被执行,请看一下:
```html

我正在使用以下代码添加力触预览操作... Peek和pop视图效果很好,但是操作不显示...请帮忙检查一下,我的代码由于某些原因没有被执行,请看一下:

```
```swift // 这里是需要翻译的 Swift 代码 ```
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {

    if (_previewActions == nil) {

        UIPreviewAction *rateAction = [UIPreviewAction actionWithTitle:@"Rate" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

            EmbededRateViewController *embededRVC = [[EmbededRateViewController alloc]initWithEmployerToRate:self.employersArray[0]];

            embededRVC.view.bounds = CGRectMake(0, 0, self.view.frame.size.width - 40, 210);
            [embededRVC setPopinTransitionStyle:BKTPopinTransitionStyleSnap];

            BKTBlurParameters *blurParameters = [[BKTBlurParameters alloc] init];

            blurParameters.tintColor = [UIColor colorWithWhite:0 alpha:0.5];
            blurParameters.radius = 0.3f; // 0.3
            [embededRVC setBlurParameters:blurParameters];
            [embededRVC setPopinTransitionDirection:BKTPopinTransitionDirectionTop];
            [self.collectionView setScrollEnabled:NO];
            [self presentPopinController:embededRVC animated:YES completion:^{
                NSLog(@"Popin presented !");
            }];
        }];

        UIPreviewAction *commentAction = [UIPreviewAction actionWithTitle:@"Comment" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

            NewCommentViewController *ncvc = [[NewCommentViewController alloc]initWithEmployer:self.employersArray[0]];
            [self presentViewController:ncvc animated:YES completion:nil];
        }];

        UIPreviewAction *reportAction = [UIPreviewAction actionWithTitle:@"Report" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

            ReportEmployerViewController *reportEmpVC = [[ReportEmployerViewController alloc]initWithEmployer:self.employersArray[0]];
            [self presentViewController:reportEmpVC animated:YES completion:nil];
        }];

        UIPreviewAction *cancelAction =
        [UIPreviewAction actionWithTitle:@"Cancel"
                                   style:UIPreviewActionStyleSelected
                                 handler:^(UIPreviewAction *action,
                                           UIViewController *previewViewController){

                                 }];

        _previewActions = @[commentAction, rateAction, reportAction, cancelAction];
    }
    return _previewActions;

}
1个回答

21

我曾经遇到过同样的问题,陷入了很长时间的困境。

我犯的错误是将这个方法添加到了Caller View Controller中。请勿在Caller View Controller中添加该方法,而是应该在Called View Controller中添加。

例如,如果您正在通过强制按压View Controller A(caller)来呈现View Controller B(called),则应将此方法添加到View Controller B(called)中。

这个错误非常明显,因为我们正在View Controller B中处理按钮动作。

希望能对你有所帮助。祝你好运。


谢谢!解决了我的问题。 - atereshkov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接