objective-c - objc 中的 UIContextMenuConfiguration

标签 objective-c ios13 xcode11

我想在 objC 中实现 UIContextMenuConfiguration

swift 中有很多例子,但我必须在 objc 中关闭一个问题...

所以我很快就找到了这样的例子

override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
    let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { actions -> UIMenu<UIAction>? in
        let action = UIAction(__title: "Custom action", image: nil, options: []) { action in
            // Put button handler here
        }
        return UIMenu<UIAction>.create(title: "Menu", children: [action])
    }
    return configuration
}

在 objc 中我无法定义操作

我只能犯错误...

这是我的示例代码...

   - (UIContextMenuConfiguration *)tableView:(UITableView *)tableView
contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
                                    point:(CGPoint)point API_AVAILABLE(ios(13.0)){


    BlogPost *blogPost = [self.blogPosts objectAtIndex:indexPath.row];

    UIAction * lettura = [UIAction actionWithTitle:@"Leggi"
                                             image:nil
                                        identifier:nil
                                           handler:^(UIAction *action){[self presentSF:indexPath];}
                          ];
UIMenu * menu = [UIMenu menuWithTitle:@"" children:@[lettura]];

    UIContextMenuConfiguration * config = [UIContextMenuConfiguration configurationWithIdentifier:nil
                                                                                  previewProvider:^ UIViewController* {
                                                                                      SFSafariViewController *previewSFController = [[SFSafariViewController alloc]                     initWithURL:blogPost.url entersReaderIfAvailable:NO];
                                                                                                previewSFController.preferredControlTintColor=[UIColor blackColor];
                                                                                                previewSFController.delegate = self;
                                                                                        return previewSFController;
                                                                                  }
                                                                                   actionProvider:nil];
    return config;
}

有人可以帮助我

提前非常感谢您的帮助

万尼

最佳答案

对不起各位

我解决了...

我只需传递一个数组...

actionProvider:^(NSArray* suggestedAction){return menu;}

关于objective-c - objc 中的 UIContextMenuConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57778350/

相关文章:

c++ - Stringstream 缓冲区在 Objective-C++ 中不会为空

crash - 打开项目时Xcode 11崩溃

react-native - 存档时"Command PhaseScriptExecution failed with a nonzero exit code"

ios - 在 iOS 13 全屏中呈现模式

swift - 如何更改 DispatchTimeInterval 以获得成员毫秒

react-native - Share 在 iOS 13 上不起作用。 Expo 模块

xcode - 运行时方向颠倒

ios - UICollectionView 中滚动或重新加载数据时出现内存泄漏问题

objective-c - 我无法更新我的 NSTableView

ios - 转到另一个 Viewcontroller