2010-08-21 2 views
0

버튼을 클릭 할 때 아이폰에서 터치 이벤트를 호출해야합니다. 다음 코드는 터치 이벤트를 호출하지 않습니다버튼을 클릭 할 때 아이폰 터치 이벤트를 호출 할 수 없습니다

이 문제를 해결하는 방법을 알려주십시오.

버튼 코드는 다음과 같습니다.

- (공극) 방법 {

BottomView = [UIView의 ALLOC] INIT];

btnRefresh = [UIButton buttonWithType : UIButtonTypeCustom]; [btnRefresh setImage : [UIImage imageNamed : @ "refresh_icon.png"] forState : UIControlStateNormal]; [str : 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 : 자기 액션 : @selector (KeyboardRefresh :) forControlEvents : UIControlEventTouchUpInside];
[btnRefresh setUserInteractionEnabled : YES]; [btnRefresh setMultipleTouchEnabled : YES];

[BottomView addSubview:btnRefresh]; 

경우 (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)]; 
} 

}

상기 Methos는 호출되고

- (무효) touchesBegan : (NSSet *)는 withEvent 접촉 : (UIEvent *) 이벤트

{ NSLog (@ "예"); }

은 새로 고침 버튼을 클릭 할 때 호출되지 않습니다.

누구든지 나를 도와 줄 수 있습니다. 미리 감사드립니다.

답변

1

touchesBegan에는 @selector가 없습니다. 대신 KeyboardRefresh를 사용하십시오. touchesBegan에서 버튼 누르기를 확인하지 마십시오. 대신 귀하의 touchesBegan을 다음으로 대체합니다 :

-(void)KeyboardRefresh:(id) sender 
{ 
    NSLog(@"yes"); 
} 
+0

감사합니다. 하지만 둘 다 호출해야하고 내가 터치 감동을 호출하고 끝을 만지는 것이 필요합니다. 새로 고침 버튼을 클릭 할 때 다른 버튼을 보여야합니다. – Ganesh

+0

잘 모르겠지만 버튼에 대해 걱정한다면 아마도 여러 주마다 여러 가지 방법을 만들고 싶을 것입니다. UIControlEventTouchUpInside –

관련 문제