我是 iOS 新手。
我正在研究警报 View 。这是我的代码。这里有 2 个警报 View :登录页面的 successfulallert
和 unsuccessfulallert
。我在这里也使用alertview delegate,它适用于两个alertview,但我只想为成功的alertview工作,并且导航应该只为成功的alertview完成。如果有人知道这一点请帮助我。
NSString *responseOfResult = [[NSString alloc]initWithString:[result response]];
NSRange match;
// NSLog(@"string= %@", str);
match = [responseOfResult rangeOfString: @"successful"];
if(match.location == NSNotFound)
{
UIAlertView *unsuccessfulAllert = [[UIAlertView alloc]
initWithTitle:@"Alert"
message:responseOfResult
delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[unsuccessfulAllert show];
}
else {
UIAlertView *successfulAllert = [[UIAlertView alloc]
initWithTitle:@"Message" message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[successfulAllert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
[[self navigationController]pushViewController:registerUserScreen animated:YES];
}
}
最佳答案
为什么不将“OK”作为cancelButtonTitle?一切都会自动处理。
UIAlertView *successfulAllert = [[UIAlertView alloc]
initWithTitle:@"Message" message:@"Login successful." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[successfulAllert show];
关于iphone - 单击警报 View 中的按钮时如何关闭警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10547821/