表格单元格中的令人敬畏的菜单检测到点击

时间:2014-04-30 21:26:27

标签: ios uitableview

您好我在每个单元格上编写一个很棒的菜单按钮,问题是我需要知道我点击了哪个Awesome Menu视图

这是我将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!");
}

1 个答案:

答案 0 :(得分:1)

您可以采取几种方法。

  1. 如果您的表中只有一个部分,则可以将每个tag对象的AwesomeMenu属性分配给indexPath.row-tableView:cellForRowAtIndexPath:的值AwesomeMenu }。

  2. 您可以向@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
  3. 或者,您可以获取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; }

    {{1}}
相关问题