views:

56

answers:

1

Hi all 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

+1  A: 

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");
}
thyrgle
Thankyou for the message. but i need to call both and also i need to call touches moved and touches end is there any idea. it has to show another button when click on refresh button.
Ganesh
I'm not sure but, if your worried about buttons you probably just want to make multiple methods for the different states. i.e UIControlEventTouchUpInside
thyrgle