如何更改适合上述iOS 9
的对象代码?我将X Code更新为8.2.1时出现此错误。代码如下
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Continue"]){
NSLog(@"Continue...");
[self performSegueWithIdentifier:@"createlogin" sender:self];
}
}
错误:
不推荐使用UIAlertView:首先在iOS 9.0中弃用 - UIAlertView 已弃用。使用UIAlertController的preferredStyle 而是UIAlertControllerStyleAlert
感谢。
答案 0 :(得分:1)
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Add Title" message:@"Add Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Here Add Your Action
}];
UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:@"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Add Another Action
}];
[alert addAction:actionOK];
[alert addAction:actionCANCEL];
[self presentViewController:alert animated:YES completion:nil];
如果有任何需要,请使用此方法,有关更多信息,请使用此链接http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
答案 1 :(得分:0)
使用此代码
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * continueButton = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
[self performSegueWithIdentifier:@"createlogin" sender:self];
}];
UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
}];
[alert addAction:continueButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
答案 2 :(得分:0)
试试这个:
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Your message title"
message:@"Enter your message here."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
NSLog(@"Ok Action");
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(@"Cancel Action");
}];
[controller addAction:okAction];
[controller addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];