我想在单击AlertView中的按钮后跳转到另一个viewController。 谁能给我一个样品?
问题更新-------
我正在尝试这种方式:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
if ([cell.reuseIdentifier isEqualToString:@"Logoff"]){
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
message:@“Logoff?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* Confirm = [UIAlertAction actionWithTitle:@“Confirm" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
[self.performSegueWithIdentifier:@"ShowLoginView" sender:self];
LoginViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:newView animated:YES];
}];
UIAlertAction* Cancel = [UIAlertAction actionWithTitle:@“Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:Confirm];
[alert addAction:Cancel];
[self presentViewController:alert animated:YES completion:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
但是我收到了这个错误: 在'GeneralSettingsTableViewController *'类型的对象上找不到属性'performSegueWithIdentifier'
我错过了什么吗?
答案 0 :(得分:0)
alertView
折旧使用UIAlertController
例如
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Info"
message:@"You are using UIAlertController"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
// here add your segue for navigation for another view Controller
// If you already created the segue use this
[self performSegueWithIdentifier:@"yoursegueName" sender:self];
// if you are used Storyboard ID use this
LoginViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:newView animated:YES];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
答案 1 :(得分:0)
尝试将传递控制传递给特定的viewController
- (void)viewDidLoad {
[super viewDidLoad];
[self showAlert];
}
-(void)showAlert{
UIAlertView *alertForCall = [[UIAlertView alloc]initWithTitle:@"" message:@"time to choose" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"Yes", nil];
[alertForCall show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1){
thirdViewController *thirdView = [self.storyboard instantiateViewControllerWithIdentifier:@"third"];
[self.navigationController pushViewController:thirdView animated:YES];
}
}