我正在尝试实现此方法:
(\\w+)(?:\\)+)
在我声明的头文件中:UIAlertController * alert;
但是我得到一个没有可见的选择器错误界面?那是为什么?
答案 0 :(得分:0)
试试这个:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No network connection" message:@"You must be connected to the internet to use this app." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:nil];
答案 1 :(得分:0)
你得到了#34;选择器错误没有可见的界面" 因为UIAlertController在其类中没有 initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles 方法;它在UIAlertView类中可用。
UIAlertView的实际实现[在iOS 9.0中已弃用];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
要在单击按钮时执行操作,请遵循UIAlertViewDelegate协议:
@interface YourViewController : UIViewController <UIAlertViewDelegate>
&安培;实现这个委托方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked OK
if (buttonIndex == 0) {
// do something here...
}
}
您可以使用UIAlertController;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
//perform Action }]];
[self presentViewController:alert animated:YES completion:nil];