简体   繁体   中英

Awesome menu in a table cell detect click

Hi im coding an awesome menu button on each cell, the problem is that I need to know which Awesome Menu view I´m clicking

This is my function to add the Awesome Menu view to each cell

    - (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;
}

This are my functions for detecting a click on the 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!");
}

There are a couple of approaches you could take.

  1. If you only have one section in your table, you could assign the tag property of each AwesomeMenu object to the value of whatever indexPath.row is in -tableView:cellForRowAtIndexPath: .

  2. You could add a property to AwesomeMenu for the purpose of identifying the row or indexPath it is located at:

     @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 
  3. Or, you could get the cell for the AwesomeMenu and then get its indexPath from the table:

     - (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; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM