1.定义对象的成员变量的时候以便使用下划线开头:例如NSImage    *_image;

 

NSURL的一个函数:

getResourceValue:forKey:error:

Returns the resource value for the property identified by a given key.

- (BOOL)getResourceValue:(id *)value forKey:(NSString *)key error:(NSError **)error

Parameters
value

The value for the property identified by key.

key

The name of one of the URL’s resource properties.

error

The error that occurred in the case that the resource value cannot be retrieved.

Return Value

YES if value is successfully populated; otherwise, NO.

Discussion

value is set to nil if the requested resource value is not defined for the URL. In this case, the method still returns YES.

NSFile类里的函数:contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error

Performs a shallow search of the specified directory and returns URLs for the contained items.

. If you need to perform a deep enumeration, use theenumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method instead.

How Modal Windows Work

You can make a whole window or panel run in application-modal fashion, using the application’s normal event loop machinery but restricting input to the modal window or panel. Modal operation is useful for windows and panels that require the user’s attention before an action can proceed. Examples include error messages and warnings, as well as operations that require input, such as open dialogs, or dialogs that apply to multiple windows.

There are two mechanisms for operating an application-modal window or panel. The first, and simpler, is to invoke the runModalForWindow: method ofNSApplication, which monopolizes events for the specified window until one of stopModal, abortModal, or stopModalWithCode: is invoked, typically by a button’s action method. The stopModal method ends the modal status of the window or panel from within the event loop. It doesn’t work if invoked from a method invoked by a timer or by a distributed object because those mechanisms operate outside of the event loop. To terminate the modal loop in these situations, you can use abortModal. The stopModal method is typically invoked when the user clicks the OK button (or equivalent), abortModal when the user clicks the Cancel button (or presses the Escape key). These two methods are equivalent to stopModalWithCode: with the appropriate argument.

The second mechanism for operating a modal window or panel, called a modal session, allows the application to perform a long operation while it still sends events to the window or panel. Modal sessions are particularly useful for panels that allow the user to cancel or modify an operation. To begin a modal session, invoke beginModalSessionForWindow: on the application, which sets the window up for the session and returns an identifier used for other session-controlling methods. At this point, the application can run in a loop that performs the operation, invoking runModalSession: on the application object on each pass so that pending events can be dispatched to the modal window. This method returns a code indicating whether the operation should continue, stop, or abort, which is typically established by the methods described above for runModalForWindow:. After the loop concludes, you can remove the window from the screen and invoke endModalSession: on the application to restore the normal event loop.

Note: You can write a modal event loop for a view object so that the object has access to all events pertaining to a particular task, such as tracking the mouse in the view. For an example, see “Responding to User Events and Actions” in “Creating a Custom View”.

The normal behavior of a modal window or session is to exclude all other windows and panels from receiving events. For windows and panels that serve as general auxiliary controls, such as menus and the Font panel, this behavior is overly restrictive. The user must be able to use menu key equivalents (such as those for Cut and for Paste) and change the font of text in the modal window, and this requires that non-modal panels be able to receive events. To support this behavior, an NSWindow subclass overrides the worksWhenModal method to return YES. This allows the window to receive mouse and keyboard events even when a modal window is present. If a subclass needs to work when a modal window is present, it should generally be a subclass of NSPanel, not ofNSWindow.

Modal windows and modal sessions provide different levels of control to the application and the user. Modal windows restrict all action to the window itself and any methods invoked from the window. Modal sessions allow the application to continue an operation while accepting input only through the modal session window. Beyond this, you can use distributed objects to perform background operations in a separate thread, while allowing the user to perform other actions with any part of the application. The background thread can communicate with the main thread, allowing the application to display the status of the operation in a non-modal panel, perhaps including controls to stop or affect the operation as it occurs. Note that because AppKit isn’t thread-safe, the background thread should communicate with a designated object in the main thread that in turn interacts with the AppKit.

Before OS X version 10.6, if a modal window was open, application termination would be prevented if the user attempted to terminate that window’s application. Beginning in OS X version 10.6, you can call setPreventsApplicationTerminationWhenModal: with a value of NO, and the window will not prevent application termination when modal. The current value of this property may be accessed by calling preventsApplicationTerminationWhenModal. The default value is NO.

最新文章

  1. 配置Spark on YARN集群内存
  2. tracer
  3. 【wikioi】1913 数字梯形问题(费用流)
  4. C#中的异常处理
  5. (转载)myeclipse项目名称重命名
  6. 【动态规划】Vijos P1218 数字游戏(NOIP2003普及组)
  7. String拼接也有用加号更好的时候
  8. poj1316
  9. C#委托的简单剖析
  10. 动态创建VIEW
  11. 使用sshpass同时更新一台ubuntu和一台CentOS
  12. UOJ#42. 【清华集训2014】Sum 类欧几里德算法
  13. node.js http接口调试时请求串行特性分析
  14. Unity3D-RayMarch-几何图元-3添加阴影
  15. ASP.Net Post方式获取数据流的一种简单写法
  16. Linux动态调频系统CPUFreq之一:概述【转】
  17. js——类型转换
  18. python爬虫实例--网易云音乐排行榜爬虫
  19. float数据类型研究,发现其能显示的有效数字极为有限
  20. 2018.10.19 bzoj1584: Cleaning Up 打扫卫生(线性dp)

热门文章

  1. mac更改本地mysql登陆密码
  2. 【js】JavaScript parser实现浅析
  3. [CREC2007/CQOI2014]robotic sort
  4. 392 Is Subsequence 判断子序列
  5. Java泛型Object和?区别
  6. Jmeter接口测试---get和post及解决乱码问题
  7. karma+requirejs+angular 测试
  8. 自学php【一】 任务:图片上传即时可见
  9. Spartan6系列之芯片配置模式详解
  10. jsp学习笔记 - 内置对象 config