Question

i need to call touch event in iphone when i clicked on a button. i have the following code which is not calling touch event

Please any one let me know how to resolve this.

The button code is as follows.

-(void)method {

BottomView = [[UIView alloc] init];

btnRefresh =[UIButton buttonWithType:UIButtonTypeCustom]; [btnRefresh setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"blue.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateNormal]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"]stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState:UIControlStateHighlighted]; [btnRefresh setBackgroundImage:[[UIImage imageNamed:@"ggrey1.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] forState: UIControlStateSelected]; [btnRefresh addTarget:self action:@selector(KeyboardRefresh:) forControlEvents:UIControlEventTouchUpInside];
[btnRefresh setUserInteractionEnabled:YES]; [btnRefresh setMultipleTouchEnabled:YES];

[BottomView addSubview:btnRefresh];

if (self.isPortrait) {

    [btnRefresh setFrame:CGRectMake(71, 0, 40, 6)];

    [BottomView setFrame:CGRectMake(0, 160, 320, 41)];
}
else{

    [btnRefresh setFrame:CGRectMake(94, 0, 61, 8)];

    [BottomView setFrame:CGRectMake(0, 123, 480, 41)];
}

}

the above methos is calling and the

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{ NSLog(@"yes"); }

is not calling when i click on refresh butotn.

can any one help me out. Thanks in advance

Was it helpful?

Solution

You don't have the @selector for touchesBegan. You instead have it for KeyboardRefresh. Don't check for button pressage in touchesBegan. Instead replaces your touchesBegan with:

-(void)KeyboardRefresh:(id) sender
{ 
    NSLog(@"yes");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top