我有这个 UIAlertController 作为一个实用程序,它接受两个参数,标题和内容。我想修改“确认”按钮。我想复制这个实用程序并添加另一个参数来执行特定的功能。
-(UIAlertController *) modalWithTitle : (NSString *) title andContent: (NSString *) content{
UIAlertController *alert = [UIAlertController alertControllerWithTitle: title message:content preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){}];
[alert addAction:defaultAction];
return alert;
}
示例代码:
UIAlertController *alert =[[ModalController alloc] modalWithTitle:@"Error" andContent:@"Network unavailable."
andAction:<ENTER FUNCTION TO EXECUTE HERE>];
[self presentViewController:alert animated:YES completion:nil];