0

I have this code i want it to get the tag value according to selected array text.

- (IBAction)Share:(UIButton*)sender
{

        menuItems =
        @[

          [KxMenuItem menuItem:@"Share"
                         image:nil
                        target:self
                        action:NULL],

          [KxMenuItem menuItem:@"Share this on Facebook"
                         image:[UIImage imageNamed:@"facebook.png"]
                        target:self
                        action:@selector(pushMenuItem:)],

          [KxMenuItem menuItem:@"Share this on Twitter"
                         image:[UIImage imageNamed:@"Twitter.png"]
                        target:self
                        action:@selector(pushMenuItem:)],


          [KxMenuItem menuItem:@"Version 1.0"
                          image:nil
                        target:self
                        action:NULL],

          ];

        first = menuItems[0];

        first.foreColor = [UIColor colorWithRed:47/255.0f green:112/255.0f blue:225/255.0f alpha:1.0];
        first.alignment = NSTextAlignmentCenter;

    [KxMenu showMenuInView:self.view fromRect:sender.frame menuItems:menuItems];


}

- (void) pushMenuItem:(id)sender
{

NSLog(@"%@",sender);

}

i want to get the tag value in sender. how may i set the tag value to this custom popup class.

Here MenuItem is Array

Jitendra
  • 5,055
  • 2
  • 22
  • 42
  • check this http://stackoverflow.com/questions/9146670/ios-uimenucontroller-uimenuitem-how-to-determine-item-selected-with-generic-sel/9874092#9874092 might be helpful for u... – Kalpesh Oct 18 '13 at 07:55

2 Answers2

1

You cant set a tag to KxMenuItem because it is a subclass of NSObject. One approach that you can use is make MenuItem a member variable and in the action method get the index as follows.

- (void) pushMenuItem:(id)sender
{
 NSLog(@"%@",sender);
 int index = [self.MenuItem indexOfObject:sender];
}
Suhas
  • 1,500
  • 11
  • 15
0

If I'm not wrong, a KXMenuItem is not a subclass of UIView, which means that there is no tag property available for free.

You could, however, either use different selectors for different menu items, or check for the title of the sender and base your decision on what it matches. For example:

- (void) pushMenuItem:(id)sender
{
   KXMenuItem *selected = (KXMenuItem*)sender;
   if ( [selected.title isEqualToString:@"Share this on Facebook"] ){
        //share on facebook
   }
   else //And so on
}
micantox
  • 5,446
  • 2
  • 23
  • 27