iOS SDK中的NSAlert.h在哪里?

jww*_*jww 9 iphone ios

根据iOS的使用和创建错误对象,可以使用以下代码显示错误对象.

NSError *theError = nil;
BOOL success = [myDoc writeToURL:[self docURL] ofType:@"html" error:&theError];

if (success == NO) {
    // Maybe try to determine cause of error and recover first.
    NSAlert *theAlert = [NSAlert alertWithError:theError];
    [theAlert runModal]; // Ignore return value.
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不够聪明,无法弄清楚如何包含NSAlert.h.

任何帮助,将不胜感激.

Dan*_*son 15

该文档指的是(OS X)AppKit框架.就在那个方框之后,它说:

(UIAlertView,对应于NSAlert的UIKit类,没有alertWithError的等效方法:.)

您仍然可以使用UIAlertView,但您需要手动填充错误中的标题,消息和按钮字符串.

  • 谢谢.为什么Apple会这样做?它管有人学习Cocoa Touch. (5认同)

rck*_*nes 5

NSAlert在UIKit中无法使用.这个例子只是OS X doc的复制品.

清单2-1中的代码使用返回的NSError立即向用户显示错误警报.(UIAlertView,对应于NSAlert的UIKit类,没有alertWithError的等效方法:.)Cocoa域中的错误对象始终是本地化的并且随时可以呈现给用户,因此它们通常可以在没有进一步评估的情况下呈现.

  • 谢谢.为什么Apple会这样做?它管有人学习Cocoa Touch.(丹尼尔得到了绿色支票,因为他是第一个回答 - 我宁愿给你们两个人一个信用). (3认同)