我想用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;
}有人能帮我吗
提前感谢您的帮助
Vanni
发布于 2019-09-04 05:02:20
对不起,你们这些人
我解决了..。
我只需要传递一个数组。
actionProvider:^(NSArray* suggestedAction){return menu;}发布于 2021-06-16 03:26:41
- (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;}
https://stackoverflow.com/questions/57778350
复制相似问题