我有两个类,它们提供了在从API获取数据时报告各种错误的委托方法。HttpAPI获取天气数据,RadarAPI获取雷达图像。下面的代码在HomeViewController中,它处理来自每个API的数据或错误。
// MARK: - HttpAPI Delegate
extension HomeViewController: HttpAPIDelegate {
func apiSessionError(_ error: Error) {
// show alert with error from url session
}
func apiHttpError(_ code: Int) {
// show alert with HTTP error code
}
func apiJsonError(_ error: Error) {
// show alert with json error
}
func apiSuccess(_ json: [String: Any]) {
// update app with weather data
}
}
// MARK: - RadarAPI Delegate
extension HomeViewController: RadarAPIDelegate {
func radarSessionError(_ error: Error) {
// show alert for url session error
}
func radarHttpError(_ code: Int) {
// show alert with HTTP response error code
}
func radarImageError(_ error: String) {
// show alert with image parsing error message
}
func radarSuccess(_ image: UIImage) {
// update app with weather radar image
}
}如果在获取天气数据或检索雷达图像时发生错误,我想显示一个警报。问题是,如果在HttpAPI中发生错误,那么RadarAPI也会给出一个错误;因此,将出现两个不推荐使用的UIAlertControllers。
如何处理多个错误消息并在单个UIAlertController中显示这些错误
发布于 2017-05-29 21:28:20
为什么不允许显示2个UIAlertControllers?
无论如何,如果你不想显示两个不同的警报,尝试执行一种机制,在决定显示什么之前,等待两个响应。
https://stackoverflow.com/questions/44243407
复制相似问题