Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:11+00:00 2026-05-22T23:35:11+00:00

I have written the code shown below. my problem is that I can’t touch

  • 0

I have written the code shown below. my problem is that I can’t touch some of the buttons. I have written that method in NSTimer method. Can anybody help in solving this problem?

One method is to create a button and another for changing the values to screen size.

-(void)createButton
{
int x=0;
int y=0;
int width=100;
int height=100;

for (int i=0; i<9; i++)
{

    UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(x ,y, width, height)];
    [button.titleLabel  setFont:[UIFont fontWithName:@"Helvetica" size:24.0]];
    NSDate *date=[NSDate date];
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
    [dateformatter setDateFormat:@"ss"];
    NSString *sec=[dateformatter stringFromDate:date];

    NSLog(@"sec is %@",sec);

    CGPoint dest= CGPointMake(arc4random() %768, arc4random() %1024);
    //CGPoint dest= CGPointMake(arc4random() %[sec intValue], arc4random() %480);
    button.tag=i;
    [button setBackgroundColor:[UIColor blackColor]];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
    //[button setImage:[UIImage imageNamed:@"thing.png"] forState:UIControlStateNormal];

    int numx=[[NSNumber numberWithInt:dest.x]intValue];
    int numy=[[NSNumber numberWithInt:dest.y]intValue];
    //button.center.x= numx+5;
    //button.center.y=numy+5;
    button.center=CGPointMake(numx+10, numy+10);

    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    [dict setValue:[NSNumber numberWithInt:5] forKey:@"Xvalue"];
    [dict setValue:[NSNumber numberWithInt:5] forKey:@"Yvalue"];
    [dict setValue:button forKey:@"Button"];

    [button addTarget:self action:@selector(buttonpressed:) forControlEvents:UIControlEventTouchUpInside];
    //[button addTarget:self action:@selector(dragBegan:withEvent:)forControlEvents: UIControlEventTouchDown];
    //[button addTarget:@selector(buttonpressed:) action:@selector(buttonpressed:) forControlEvents:UIControlStateSelected];
    [button addTarget:self action:@selector(dragMoving:withEvent:)forControlEvents: UIControlEventTouchDragInside];     
    [button addTarget:self action:@selector(dragEnded:withEvent:)forControlEvents: UIControlEventTouchUpInside |
    UIControlEventTouchUpOutside];
    [self.buttonArray addObject:dict];
    [self.view addSubview:button];
    [button release];
    x+=50;

}


}

-(void)timerMethod
{

for(NSMutableDictionary *dict in self.buttonArray)
{
    UIButton *but=[dict objectForKey:@"Button"];
    CGPoint bcenter=but.center;
    int numx=[[dict objectForKey:@"Xvalue"]intValue];
    int numy=[[dict objectForKey:@"Yvalue"]intValue];

    bcenter.x+=numx;
    bcenter.y+=numy;
    //bcenter.x=bcenter.x+[dict objectForKey:@"Xvalue"];
    //bcenter.y=bcenter.y+[dict objectForKey:@"Yvalue"];

    but.center=bcenter;

    if(bcenter.x>720)
    {
        [dict setValue:[NSNumber numberWithInt:-10] forKey:@"Xvalue"];

    }
    if(bcenter.y>1000)
    {
        [dict setValue:[NSNumber numberWithInt:-10] forKey:@"Yvalue"];

    }
    if(bcenter.x<15)
    {
        [dict setValue:[NSNumber numberWithInt:10] forKey:@"Xvalue"];
    }

    if(bcenter.y<15)
    {
        [dict setValue:[NSNumber numberWithInt:10] forKey:@"Yvalue"];
    }



}



}

-(void)buttonpressed:(id)sender
{

    NSLog(@"sender tag is %d",[sender tag]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:35:12+00:00Added an answer on May 22, 2026 at 11:35 pm

    try set target:self action:buttonpressed

    I think you forget to do that , the function will be fired when you click it

    [button addTarget:self action:@selector(buttonpressed:) forControlEvents:UIControlEventTouchUpInside];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code that pulls info from a plist file and does
I have written is code below, but button isn't shown because i've set FILL_PARENT
I have written code that automatically creates CSS sprites based on the IMG tags
I have written some code in my VB.NET application to send an HTML e-mail
Put it another way: what code have you written that cannot fail. I'm interested
I have a code snippet written in PHP that pulls a block of text
I have some code I've written in PHP for consuming our simple webservice, which
I have written the below code to validate the value in the string before
I have written a working token parser based on the code shown at spirit
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.