Как применить несколько событий на одной кнопке? - PullRequest
0 голосов
/ 19 октября 2011

У меня есть кнопка, на которой я хочу установить несколько событий.Когда пользователь нажимает кнопку в первый раз, то я меняю фоновое изображение, а когда пользователь снова нажимает кнопку, затем сбрасываю первое изображение.Как это сделать с кнопкой?

Заранее спасибо ...

Ответы [ 5 ]

0 голосов
/ 19 октября 2011
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;
    }
}
0 голосов
/ 19 октября 2011
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];
    }

}
0 голосов
/ 19 октября 2011

Попробуйте следующее

    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 
       }
   }
0 голосов
/ 19 октября 2011
- (void)changeBG {

  BOOL flag = TRUE;

  if (flag == TRUE) {

    // first background
    flag = FLASE;

  } else {

     // second background    
     flag = TRUE;
   }
}

Вызовите вышеуказанный метод в вашем методе buttonTouchUPInside.

0 голосов
/ 19 октября 2011

Вам не нужно иметь несколько событий, просто вызовите одну функцию и в этой функции измените фон (имея какой-то индикатор, какой фон отображать -> i здесь)

- (void)changeBackground {
  i = (i+1)%2;

  if (i == 0)
    // first background
  else 
    // second background    
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...