UIContextMenuConfiguration in objc



我想在objC中实现UIContextMenuConfiguration

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

所以在 swift 中我找到了这样的例子

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;}
- (UIContextMenuConfiguration*)tableView:(UITableView*)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath*)indexPath point:(CGPoint)point

{

UIContextMenuConfiguration* config = [UIContextMenuConfiguration configurationWithIdentifier:nil
       previewProvider:nil
        actionProvider:^UIMenu* _Nullable(NSArray<UIMenuElement*>* _Nonnull suggestedActions) {
NSMutableArray* actions = [[NSMutableArray alloc] init];
//Your Action
[actions addObject:[UIAction actionWithTitle:@"Favoritar!" image:[UIImage systemImageNamed:@"star"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
[self updateFavoriteTournament:self.tournamentArray[indexPath.row][@"_id"]];
}]];


UIMenu* menu = [UIMenu menuWithTitle:@"" children:actions];
return menu;
}];
return config;

}

相关内容

  • 没有找到相关文章

最新更新