action:@selector (showAlert:), как передать параметр в этом showAlert методе?

Можно также использовать Google Maps API с собственными изображениями. Конечно, они не должны быть картой; они могут быть любыми изображениями. Это позволит пользователю перетаскивать и масштабировать, как в картах Google.

6
задан jszumski 1 May 2013 в 17:56
поделиться

2 ответа

That's not possible. You have to create a method conforming to IBAction

- (IBAction)buttonXYClicked:(id)sender;

In this method you can create and call the UIAlertView. Don't forget to connect the button with the method in Interface Builder.

If you like to distinguish between multiple Buttons (e.g. you have one in each table cell) you can set the tag property of the button. And then check sender.tag from which button the click comes.

2
ответ дан 9 December 2019 в 20:46
поделиться

Если вы используете кнопку в Tableviewcell, тогда вам нужно добавить значение тега к кнопке каждой ячейки и установить метод addTarget с идентификатором в качестве параметра.

Пример кода:

У вас есть для ввода кода ниже в методе cellForRowAtIndexPath .

{

     // Set tag to each button
        cell.btn1.tag = indexPath.row; 
        [cell.btn1 setTitle:@"Select" forState:UIControlStateNormal];  // Set title 

     // Add Target with passing id like this
        [cell.btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];    


     return cell;

}

-(void)btnClick:(id)sender
{

    UIButton* btn = (UIButton *) sender;

     // here btn is the selected button...
        NSLog(@"Button %d is selected",btn.tag); 


    // Show appropriate alert by tag values
}
9
ответ дан 9 December 2019 в 20:46
поделиться