Monday 10 June 2013

Tap Button to Show MenuController in Xcode

.h File:

@interface ViewController : UIViewController
{
    IBOutlet UIButton *btn1;
    IBOutlet UIButton *btn2;
    IBOutlet UIButton *btn3;
    IBOutlet UIButton *btn4;

    int btnnumber;
}

-(IBAction)btn1:(id)sender;
-(IBAction)btn2:(id)sender;
-(IBAction)btn3:(id)sender;
-(IBAction)btn4:(id)sender;

@end



.m File:

-(IBAction)btn1:(id)sender
{
    [self becomeFirstResponder];
    
    btnnumber = 1;
    
    UIMenuItem *menu1=[[UIMenuItem alloc]initWithTitle:@"Detail" action:@selector(Detail:)];
    UIMenuItem *menu2=[[UIMenuItem alloc]initWithTitle:@"Edit" action:@selector(Edit:)];
    UIMenuItem *menu3=[[UIMenuItem alloc]initWithTitle:@"Change Color" action:@selector(Color:)];
    UIMenuItem *menu4=[[UIMenuItem alloc]initWithTitle:@"Delete" action:@selector(Delete:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems=[NSArray arrayWithObjects:menu1,menu3,menu2,menu4, nil];
    [menu setTargetRect:CGRectMake(0, 0, 0, 0) inView:btn1];
    [menu setMenuVisible:YES animated:YES];
}

-(IBAction)btn2:(id)sender
{
    [self becomeFirstResponder];
    
    btnnumber = 2;
    
    UIMenuItem *menu1=[[UIMenuItem alloc]initWithTitle:@"Detail" action:@selector(Detail:)];
    UIMenuItem *menu2=[[UIMenuItem alloc]initWithTitle:@"Edit" action:@selector(Edit:)];
    UIMenuItem *menu3=[[UIMenuItem alloc]initWithTitle:@"Change Color" action:@selector(Color:)];
    UIMenuItem *menu4=[[UIMenuItem alloc]initWithTitle:@"Delete" action:@selector(Delete:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems=[NSArray arrayWithObjects:menu1,menu3,menu2,menu4, nil];
    [menu setTargetRect:CGRectMake(0, 0, 0, 0) inView:btn2];
    [menu setMenuVisible:YES animated:YES];
}

-(IBAction)btn3:(id)sender
{
    [self becomeFirstResponder];
    
    btnnumber = 3;
    
    UIMenuItem *menu1=[[UIMenuItem alloc]initWithTitle:@"Detail" action:@selector(Detail:)];
    UIMenuItem *menu2=[[UIMenuItem alloc]initWithTitle:@"Edit" action:@selector(Edit:)];
    UIMenuItem *menu3=[[UIMenuItem alloc]initWithTitle:@"Change Color" action:@selector(Color:)];
    UIMenuItem *menu4=[[UIMenuItem alloc]initWithTitle:@"Delete" action:@selector(Delete:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems=[NSArray arrayWithObjects:menu1,menu3,menu2,menu4, nil];
    [menu setTargetRect:CGRectMake(0, 0, 0, 0) inView:btn3];
    [menu setMenuVisible:YES animated:YES];
}

-(IBAction)btn4:(id)sender
{
    [self becomeFirstResponder];
    
    btnnumber = 4;
    
    UIMenuItem *menu1=[[UIMenuItem alloc]initWithTitle:@"Detail" action:@selector(Detail:)];
    UIMenuItem *menu2=[[UIMenuItem alloc]initWithTitle:@"Edit" action:@selector(Edit:)];
    UIMenuItem *menu3=[[UIMenuItem alloc]initWithTitle:@"Change Color" action:@selector(Color:)];
    UIMenuItem *menu4=[[UIMenuItem alloc]initWithTitle:@"Delete" action:@selector(Delete:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems=[NSArray arrayWithObjects:menu1,menu3,menu2,menu4, nil];
    [menu setTargetRect:CGRectMake(0, 0, 0, 0) inView:btn4];
    [menu setMenuVisible:YES animated:YES];
}

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

-(void)Detail:(id)sender
{
    NSLog(@"Table Details");
    NSLog(@"%d",btnnumber);
}


-(void)Edit:(id)sender
{
    NSLog(@"Edit Table");
    NSLog(@"%d",btnnumber);
}


-(void)Color:(id)sender
{
    NSLog(@"Change Table Color");
    NSLog(@"%d",btnnumber);
    
    UIMenuItem *menu1=[[UIMenuItem alloc]initWithTitle:@"Default" action:@selector(Default:)];
    UIMenuItem *menu2=[[UIMenuItem alloc]initWithTitle:@"Red" action:@selector(Red:)];
    UIMenuItem *menu3=[[UIMenuItem alloc]initWithTitle:@"White" action:@selector(White:)];
    UIMenuItem *menu4=[[UIMenuItem alloc]initWithTitle:@"Yellow" action:@selector(Yellow:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems=[NSArray arrayWithObjects:menu1,menu3,menu2,menu4, nil];
    [menu setTargetRect:CGRectMake(0, 0, 0, 0) inView:btn1];
    [menu setMenuVisible:YES animated:YES];
}

-(void)Default:(id)sender
{
    NSLog(@"you have chossed default color");
}

-(void)Red:(id)sender
{
    NSLog(@"you have chossed Red color");
}

-(void)White:(id)sender
{
    NSLog(@"you have chossed White color");
}

-(void)Yellow:(id)sender
{
    NSLog(@"you have chossed Yellow color");
}

-(void)Delete:(id)sender
{
    NSLog(@"Delete Table");
    NSLog(@"%d",btnnumber);
    
}


xib File (Design):




OutPut:


Click the Btn1. Show the Options in MenuController

Click the change Color from Menu Controller




Choose the Color is White(Another MenuControler)


Click the Btn3. Show the Options Available in MenuController



Create a Apple ID for Free!!!

Steps for Creating Free Apple ID:

  1. Open the iTunes Application.

  2. Click the iTunes Store in iTunes Application

  3. In Bottom of the Page, Change the Country (Eg: Change the Country India to USA)

  4. Click and Download the free app in iTunes Store.

  5. In PopupWindow, Choose  "Create Apple ID".

  6. Continue --> Tick, I have read and agree to these Terms Conditions. --> Click the Agree Button.

  7. Enter the AppleID Details.(Email, Password, Security Questions, DOB etc). And Click Next Button.

  8. Select the Payment Option is None. And Enter the Billing Address. And Click the Create Apple ID.

---------------------------Successfully your Apple ID was Created!!!!!--------------------------------------