您好,我在每个单元格上编写了一个很棒的菜单按钮,问题是我需要知道我单击的是哪个很棒的菜单视图
这是我将Awesome Menu视图添加到每个单元格的功能
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ActivasTableViewCell";
ActivasTableViewCell *cell = (ActivasTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ActivasTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
UIImage *storyMenuItemImage = [UIImage imageNamed:@"bg-menuitem.png"];
UIImage *storyMenuItemImagePressed = [UIImage imageNamed:@"bg-menuitem-highlighted.png"];
UIImage *starImage = [UIImage imageNamed:@"icon-star.png"];
AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
NSArray *menus = [NSArray arrayWithObjects:starMenuItem1, starMenuItem2,nil];
AwesomeMenuItem *startItem = [[AwesomeMenuItem alloc] initWithImage:[UIImage imageNamed:@"bg-addbutton.png"]
highlightedImage:[UIImage imageNamed:@"bg-addbutton-highlighted.png"]
ContentImage:[UIImage imageNamed:@"icon-plus.png"]
highlightedContentImage:[UIImage imageNamed:@"icon-plus-highlighted.png"]];
AwesomeMenu *menu = [[AwesomeMenu alloc] initWithFrame:self.view.bounds startItem:startItem optionMenus:menus];
menu.delegate = self;
menu.menuWholeAngle = M_PI_2*3;
menu.farRadius = 50.0f;
menu.endRadius = 50.0f;
menu.nearRadius = 30.0f;
menu.animationDuration = 0.3f;
menu.startPoint = CGPointMake(290.0,166.0);
[cell addSubview:menu];
return cell;
}
这是我检测视图点击的功能
- (void)awesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx
{
NSLog(@"Select the index : %d",idx);
}
- (void)awesomeMenuDidFinishAnimationClose:(AwesomeMenu *)menu {
NSLog(@"Menu was closed!");
}
- (void)awesomeMenuDidFinishAnimationOpen:(AwesomeMenu *)menu {
NSLog(@"Menu is open!");
}
最佳答案
您可以采取几种方法。
如果表中只有一个部分,则可以将每个tag
对象的AwesomeMenu
属性分配给indexPath.row
中任何-tableView:cellForRowAtIndexPath:
的值。
您可以向AwesomeMenu
添加属性,以标识其位于的行或indexPath:
@interface AwesomeMenu : NSObject
...
@property (nonatomic) int rowIndex; // If you only need the row index
@property (nonatomic, strong) NSIndexPath *indexPath; // If you need row and section
...
@end
或者,您可以获取
AwesomeMenu
的单元格,然后从表中获取其indexPath
:- (void)awesomeMenuDidFinishAnimationClose:(AwesomeMenu *)menu {
UITableViewCell *cell = [self getTableViewCellForView: menu];
NSIndexPath *indexPath = [self.myMenuTable indexPathForCell: cell];
}
- (UITableViewCell *) getTableViewCellForView: (UIView *) view {
UIView *parentView = view;
while (parentView) {
if ([parentView isKindOfClass: [UITableViewCell class]]) {
return (UITableViewCell *) parentView;
}
parentView = parentView.superview;
}
return nil;
}
关于ios - 表格单元中的超赞菜单可检测点击,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23398316/