Добавьте три кнопки в UIAlertView
Я создал uialertview и добавил две кнопки. Теперь мне нужно добавить еще одну кнопку в виде предупреждения. Как отредактировать мой код, чтобы добавить еще одну кнопку?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Refresh" message:@"Are you want to Refresh Data" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
Ответы
Ответ 1
Если вы действительно пытаетесь найти решение, следующий код может вам помочь.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Refresh"
message:@"Are you want to Refresh Data"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", @"Done", nil];
[alert show];
[alert release];
Ответ 2
Вы также можете сделать свой класс делегатом UIAlertViewDelegate и выполнить все функциональные возможности ваших кнопок:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
//
}
else if (buttonIndex == 1) {
//
}
else if (buttonIndex == 2) {
//
}
else if (buttonIndex == 3) {
//
}
}
Ответ 3
Попробуйте добавить свои кнопки в otherButtonTitles
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Refresh" message:@"Are you want to Refresh Data" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1",@"Button2"@"Button2",nil];
Ответ 4
В iOS11/Swift 4 это так просто:
let alert = UIAlertController(title: "Saving Demo.", message: "Do you wish to save this Demo Settings?", preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {
(_)in
//SAVE DEMO DATA HERE
})
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: {
(_)in
//do something
})
let thirdAction = UIAlertAction(title: "3rd Btn", style: UIAlertActionStyle.default, handler: {
(_)in
//do another thing
})
alert.addAction(OKAction)
alert.addAction(cancelAction)
alert.addAction(thirdAction)
self.present(alert, animated: true, completion: nil)
Ответ 5
Попробуйте следующее:
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Refresh"
message:@"Are you want to Refresh Data"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// code here...
}];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// code here...
}];
UIAlertAction* done = [UIAlertAction
actionWithTitle:@"Done"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// code here...
}];
[alert addAction:ok] ;
[alert addAction:done];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];