여러 개의 이벤트를 설정하려는 버튼이 있습니다. 사용자가 처음 버튼을 터치하면 배경 이미지가 변경되고 사용자가 버튼을 다시 터치하면 첫 번째 이미지가 재설정됩니다. 버튼으로 어떻게 할 수 있습니까? 사전에단일 버튼에 여러 이벤트를 적용하는 방법은 무엇입니까?
감사합니다 ...
당신은, 여러 이벤트가 하나 개의 함수를 호출하고이 함수에서 배경 (배경 표시하는 지표의 일종 필요 - 여기>i
)를 변경할 필요가 없습니다
여러 개의 이벤트를 설정하려는 버튼이 있습니다. 사용자가 처음 버튼을 터치하면 배경 이미지가 변경되고 사용자가 버튼을 다시 터치하면 첫 번째 이미지가 재설정됩니다. 버튼으로 어떻게 할 수 있습니까? 사전에단일 버튼에 여러 이벤트를 적용하는 방법은 무엇입니까?
감사합니다 ...
당신은, 여러 이벤트가 하나 개의 함수를 호출하고이 함수에서 배경 (배경 표시하는 지표의 일종 필요 - 여기>i
)를 변경할 필요가 없습니다
- (void)changeBackground {
i = (i+1)%2;
if (i == 0)
// first background
else
// second background
}
다음과 같이 해보십시오
int i = 0;
-(void) buttonPressed{
i++;
if(i == 1){
//Here load the view which you want to load on first touch to a button
}
else{
//Here load the other view
}
}
- (void)changeBG {
BOOL flag = TRUE;
if (flag == TRUE) {
// first background
flag = FLASE;
} else {
// second background
flag = TRUE;
}
}
buttonTouchUPInside 메소드에서 위 메소드를 호출하십시오.
in Button action
-(void)clickOnCheckButton:(id)sender
{
UIButton *btn_tmp=sender;
if(!(btn_tmp.selected))
{
//you can set your image
[btn_tmp setSelected:YES];
}
else {
//you can set your image
[btn_tmp setSelected:NO];
}
}
try it
- (IBAction)buttonPressed:(id)sender{
static int counter;
if (counter == 0){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"ONE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else if (counter == 1){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"TWO" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else if (counter == 2){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"THREE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
counter += 1;
if (counter >2){
counter = 0;
}
}
는이 질문으로 내 대답을 얻을 : -http : 사람이 다른 대답을 //stackoverflow.com/questions/4789546/objective-c-one-button-with-multiple-sequential-outcomes 경우 그럼 내가 받아 들일거야. 감사... – iRavan12