嗨,我在每个单元格上编写了一个很棒的菜单按钮,问题是我需要知道我点击的是哪个很棒的菜单 View
这是我为每个单元格添加 Awesome Menu View 的功能
- (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;
}
这是我检测 View 点击的函数
- (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!");
}
最佳答案
您可以采用多种方法。
如果您的表中只有一个部分,您可以将每个
AwesomeMenu
对象的tag
属性分配给任何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/