﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-张运涛-文章分类-iphone</title><link>http://www.cppblog.com/zhangyuntaoshe/category/14363.html</link><description>c++</description><language>zh-cn</language><lastBuildDate>Mon, 24 Oct 2011 08:38:39 GMT</lastBuildDate><pubDate>Mon, 24 Oct 2011 08:38:39 GMT</pubDate><ttl>60</ttl><item><title>OC 语法细节</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/158976.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 24 Oct 2011 06:17:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/158976.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/158976.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/158976.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/158976.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/158976.html</trackback:ping><description><![CDATA[<div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 5px; padding-bottom: 1px; padding-left: 5px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">1.<br />isKindOfClass:</code>&nbsp;returns YES if the receiver is an instance of the specified class or an instance of any class that inherits from the specified class.</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 5px; padding-bottom: 1px; padding-left: 5px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">isMemberOfClass:</code>&nbsp;returns YES if the receiver is an instance of the specified class.</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">Most of the time you want to use&nbsp;<code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 5px; padding-bottom: 1px; padding-left: 5px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">isKindOfClass:</code>&nbsp;to ensure that your code also works with subclasses.</p></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/158976.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2011-10-24 14:17 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/158976.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>object-c object serize</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/157127.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Thu, 29 Sep 2011 04:15:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/157127.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/157127.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/157127.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/157127.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/157127.html</trackback:ping><description><![CDATA[<div>
<p>示例代码：NSArrayTest.h</p>
<p><br />
</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>1</p>
             </td>
             <td valign="top">
             <p>#import &lt;Foundation/Foundation.h&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>2</p>
             </td>
             <td valign="top">
             <p>#define FILE_NAME @"/tmp/data.txt"</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>3</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>4</p>
             </td>
             <td valign="top">
             <p><strong>@interface</strong> <strong>NSArrayTest</strong> : <strong>NSObject</strong> {</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>5</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>6</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>7</p>
             </td>
             <td valign="top">
             <p>-(void) Test;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>8</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>9</p>
             </td>
             <td valign="top">
             <p><strong>@end</strong></p>
             </td>
         </tr>
     </tbody>
</table>
<p>NSArrayTest.m</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>01</p>
             </td>
             <td valign="top">
             <p>#import "NSArrayTest.h"</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>02</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>03</p>
             </td>
             <td valign="top">
             <p><strong>@implementation</strong> <strong>NSArrayTest</strong></p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>04</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>05</p>
             </td>
             <td valign="top">
             <p>-(void) Test</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>06</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>07</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSArray</strong> *arr = [<strong>NSArray</strong> arrayWithObjects:@"one",@"two",@"three",<strong>nil</strong>];//注:最后一个要以nil结尾</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>08</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[arr writeToFile:FILE_NAME atomically:<strong>YES</strong>];//(序列化为xml格式后)保存文件</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>09</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>10</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSArray</strong> *arr2 = [<strong>NSArray</strong> arrayWithContentsOfFile:FILE_NAME];//read file</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>11</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSLog</strong>(@"%@",arr2);</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>12</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>13</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>14</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>15</p>
             </td>
             <td valign="top">
             <p><strong>@end</strong></p>
             </td>
         </tr>
     </tbody>
</table>
<p>运行结果：</p>
<p>2011-03-03 14:20:01.501 pList[1246:a0f] (</p>
<p>&nbsp;&nbsp;&nbsp; one,</p>
<p>&nbsp;&nbsp;&nbsp; two,</p>
<p>&nbsp;&nbsp;&nbsp; three</p>
<p>)</p>
<p>如果查看/tmp/data.txt，能看到下面的内容：</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>1</p>
             </td>
             <td valign="top">
             <p>&lt;?<strong>xml</strong> version="1.0" encoding="UTF-8"?&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>2</p>
             </td>
             <td valign="top">
             <p>&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "<a href="http://www.apple.com/DTDs/PropertyList-1.0.dtd">http://www.apple.com/DTDs/PropertyList-1.0.dtd</a>"&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>3</p>
             </td>
             <td valign="top">
             <p>&lt;<strong>plist</strong> version="1.0"&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>4</p>
             </td>
             <td valign="top">
             <p>&lt;<strong>array</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>5</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong>string</strong>&gt;one&lt;/<strong>string</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>6</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong>string</strong>&gt;two&lt;/<strong>string</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>7</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong>string</strong>&gt;three&lt;/<strong>string</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>8</p>
             </td>
             <td valign="top">
             <p>&lt;/<strong>array</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>9</p>
             </td>
             <td valign="top">
             <p>&lt;/<strong>plist</strong>&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<p>即NSArray默认是以xml格式来序列化对象的.</p>
<p>如果你用来存放数据的类是自己定义的，并不是上面这些预置的对象，那么就要借助正式协议NSCoding来实现序列化和反序列化。</p>
<p><br />
</p>
<p>比如，我们有一个自己的类Sample.h</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>01</p>
             </td>
             <td valign="top">
             <p>#import &lt;Foundation/Foundation.h&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>02</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>03</p>
             </td>
             <td valign="top">
             <p><strong>@interface</strong> Sample : <strong>NSObject</strong>&lt;<strong>NSCoding</strong>&gt; {</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>04</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>05</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSString</strong>* name;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>06</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;int magicNumber;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>07</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;float shoeSize;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>08</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSMutableArray</strong> *subThingies;&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>09</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>10</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>11</p>
             </td>
             <td valign="top">
             <p><strong>@property</strong>(<strong>copy</strong>) <strong>NSString</strong>* name;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>12</p>
             </td>
             <td valign="top">
             <p><strong>@property</strong> int magicNumber;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>13</p>
             </td>
             <td valign="top">
             <p><strong>@property</strong> float shoeSize;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>14</p>
             </td>
             <td valign="top">
             <p><strong>@property</strong> (retain) <strong>NSMutableArray</strong> *subThingies;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>15</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>16</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>17</p>
             </td>
             <td valign="top">
             <p>-(id) initWithName:(<strong>NSString</strong> *)n magicNumber:(int)m shoeSize:(float) ss;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>18</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>19</p>
             </td>
             <td valign="top">
             <p><strong>@end</strong></p>
             </td>
         </tr>
     </tbody>
</table>
<p>这里我们定义几个不同类型的属性，有字符串，有整数，有浮点数，还有一个可变长的数组对象</p>
<p><br />
</p>
<p>Sample.m</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>01</p>
             </td>
             <td valign="top">
             <p>#import "Sample.h"</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>02</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>03</p>
             </td>
             <td valign="top">
             <p><strong>@implementation</strong> Sample</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>04</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>05</p>
             </td>
             <td valign="top">
             <p><strong>@synthesize</strong> name;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>06</p>
             </td>
             <td valign="top">
             <p><strong>@synthesize</strong> magicNumber;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>07</p>
             </td>
             <td valign="top">
             <p><strong>@synthesize</strong> shoeSize;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>08</p>
             </td>
             <td valign="top">
             <p><strong>@synthesize</strong> subThingies;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>09</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>10</p>
             </td>
             <td valign="top">
             <p>-(id) initWithName:(<strong>NSString</strong> *)n magicNumber:(int)m shoeSize:(float)ss</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>11</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>12</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>if</strong> (<strong>self</strong>=[<strong>super</strong> init])</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>13</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>14</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.name = n;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>15</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.magicNumber = m;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>16</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.shoeSize = ss;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>17</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.subThingies = [<strong>NSMutableArray</strong> array];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>18</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>19</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return</strong> (<strong>self</strong>);</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>20</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>21</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>22</p>
             </td>
             <td valign="top">
             <p>-(void) dealloc</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>23</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>24</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[name release];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>25</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[subThingies release];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>26</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[<strong>super</strong> dealloc];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>27</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>28</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>29</p>
             </td>
             <td valign="top">
             <p>//将对象编码(即:序列化)</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>30</p>
             </td>
             <td valign="top">
             <p>-(void) encodeWithCoder:(<strong>NSCoder</strong> *)aCoder</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>31</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>32</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[aCoder encodeObject:name forKey:@"name"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>33</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[aCoder encodeInt:magicNumber forKey:@"magicNumber"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>34</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[aCoder encodeFloat:shoeSize forKey:@"shoeSize"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>35</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[aCoder encodeObject:subThingies forKey:@"subThingies"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>36</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>37</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>38</p>
             </td>
             <td valign="top">
             <p>//将对象解码(反序列化)</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>39</p>
             </td>
             <td valign="top">
             <p>-(id) initWithCoder:(<strong>NSCoder</strong> *)aDecoder</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>40</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>41</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>if</strong> (<strong>self</strong>=[<strong>super</strong> init])</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>42</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>43</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.name = [aDecoder decodeObjectForKey:@"name"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>44</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.magicNumber = [aDecoder decodeIntForKey:@"magicNumber"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>45</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.shoeSize = [aDecoder decodeFloatForKey:@"shoeSize"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>46</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>self</strong>.subThingies = [aDecoder decodeObjectForKey:@"subThingies"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>47</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>48</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return</strong> (<strong>self</strong>);</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>49</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>50</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>51</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>52</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>53</p>
             </td>
             <td valign="top">
             <p>-(<strong>NSString</strong>*) description</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>54</p>
             </td>
             <td valign="top">
             <p>{</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>55</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSString</strong> *description = [<strong>NSString</strong> stringWithFormat:@"%@:%d/%.1f %@",name,magicNumber,shoeSize,subThingies];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>56</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return</strong> (description);</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>57</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>58</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>59</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>60</p>
             </td>
             <td valign="top">
             <p><strong>@end</strong></p>
             </td>
         </tr>
     </tbody>
</table>
<p>注意其中的：encodeWithCoder与initWithCoder，这是NSCoding协议中定义的二个方法，用来实现对象的编码与解码。其实现也不复杂，利用的是key-value的经典哈希结构。当然一般在编码中，对于key的名字字符串，建议用define以常量方式事先定义好，以避免开发人员字符串键入错误。</p>
<p>测试一下：</p>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>01</p>
             </td>
             <td valign="top">
             <p>#import &lt;Foundation/Foundation.h&gt;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>02</p>
             </td>
             <td valign="top">
             <p>#import "Sample.h"</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>03</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>04</p>
             </td>
             <td valign="top">
             <p>int main (int argc, <strong>const</strong> char * argv[]) {</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>05</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSAutoreleasePool</strong> * pool = [[<strong>NSAutoreleasePool</strong> alloc] init];&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>06</p>
             </td>
             <td valign="top">
             <p>&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>07</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;Sample *s1 = [[Sample alloc] initWithName:@"thing1" magicNumber:42 shoeSize:10.5];&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>08</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[s1.subThingies addObject:@"1"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>09</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[s1.subThingies addObject:@"2"];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>10</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSLog</strong>(@"%@",s1);&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>11</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSData</strong>&nbsp; *data1 = [<strong>NSKeyedArchiver</strong> archivedDataWithRootObject:s1];//将s1序列化后,保存到NSData中</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>12</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[s1 release];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>13</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[data1 writeToFile:@"/tmp/data.txt" atomically:<strong>YES</strong>];//持久化保存成物理文件</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>14</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>15</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSData</strong> *data2 = [<strong>NSData</strong> dataWithContentsOfFile:@"/tmp/data.txt"];//读取文件</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>16</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;Sample *s2 = [<strong>NSKeyedUnarchiver</strong> unarchiveObjectWithData:data2];//反序列化&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>17</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>NSLog</strong>(@"%@",s2);</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>18</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>19</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;[pool drain];</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>20</p>
             </td>
             <td valign="top">
             <p>&nbsp;&nbsp;&nbsp;&nbsp;<strong>return</strong> 0;</p>
             </td>
         </tr>
     </tbody>
</table>
<table cellspacing="0" cellpadding="0">
     <tbody>
         <tr>
             <td valign="top">
             <p>21</p>
             </td>
             <td valign="top">
             <p>}</p>
             </td>
         </tr>
     </tbody>
</table>
</div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/157127.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2011-09-29 12:15 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/157127.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iphone 本地化</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/151791.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 25 Jul 2011 07:26:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/151791.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/151791.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/151791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/151791.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/151791.html</trackback:ping><description><![CDATA[ <img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/151791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2011-07-25 15:26 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/151791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xcode使用2</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/141890.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Tue, 15 Mar 2011 07:52:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/141890.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/141890.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/141890.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/141890.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/141890.html</trackback:ping><description><![CDATA[<p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">j)Xcode中书签的使用</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">如果你要将代码中的某个部分标注起来，以便以后和方便的找它这部分代码，则我们可以使用书签。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">选中一段文本或在源文件中放入插入点，然后选择Edit-&gt;Add to Bookmarks（快捷键&nbsp;<strong style="line-height: normal; "><span style="line-height: normal; text-decoration: underline; "><span style="line-height: normal; color: rgb(0, 0, 255); ">command + D</span></span></strong>),出现提示时输入书签名。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">k)代码编辑器的导航条</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">导航条 就是在本文编辑窗口的顶部。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">导航条上有个功能菜单，我们可以通过#pragma mark命令向 功能菜单上添加项。#pragma指令将objective-c将常规代码之外的信息或说明传递给编译器和代码器。通常，#pragma是被忽略，如果你的编译器不认识它就会忽略它，不会报考警告。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">除了通过#pragma mark向功能菜单添加项；</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在注释中以如下关键字符打头的文本都会被添加到功能菜单：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">MARK:</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">TODO:</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">FIXME:</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">!!!:</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">???:</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/ZbiXwdTcetdrAAvkBHOB7w==/4263782947214351199.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/5a627f54accee207574e00d6.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 18px; font-size: 12px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">L)通过研究助手（Research Assistant）获取Xcode 的文档和参考资料。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">可以通过Help-&gt;Show Research Assistant 打开研究助手；一旦研究助手的浮动窗口被打开后，浮动窗口中的内容会随着你与Xcode 交互操作的内容改变而改变。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">如下图所示：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在Tire.m文件中，当光标在NSString类上时，研究助手浮动窗口所显示的信息：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/EZwkgJOtPno65SPx_a_-wQ==/2254333088476433935.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/c73fa45878e48c8d9d8204d6.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">切换到文件Tire.h中，研究助手的浮动窗口就显示有关NSObject的信息：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/yAaP11AjQ4uLlmx1Fv7wsQ==/5389401379080301696.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/407885de376fee0bcdbf1ad6.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">M)文档管理程序</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">我们可以通过访问苹果公司的官方API文档；方法是按住Option键并双击某个要查看的符号。如我们按住Option键并双击NSString符号将在文档浏览器窗口中打开有关NSString的资料信息，如下图：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/rCEROoKOLb5ztvxp4Rkt-Q==/2589569785738746139.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/0df3e758615253d2810a18d6.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">按住control键并单击文档区域来打开pop菜单，选择任何菜单项，在另一个窗口中打开该文档。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "></span></span>&nbsp;</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">M)如何调试程序？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "></span></span>&nbsp;</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">（a）有两种方法：一是暴力调试，二是使用调试器调试。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">什么是暴力调试？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">暴力调试就是在你的程序中添加NSLog（）语言，将程序的控制流程和一些重要数据输出到终端上。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "></span></span>&nbsp;</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">调试器调试：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">调试器 就是介于你编写的应用程序和操作系统之间的一种程序，可以对你的程序进行控制，如停止，执行，单步跟踪等。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Xcode使用的调试器是GDB。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Xcode除了有GDB外，还有一个微型调试器，它是一个浮动窗口，通过它我们能接跳过GDB调试器做一些简单的调试工作。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Xcode有一个提供大量概述信息的调试窗口。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Xcode提供一个调试控制台，通过它可以直接向调试器发调试命令。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">（b）如何用调试器进行调试？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; （1）编译程序时必须使用编译器的Debug配置，这样编译出的程序包含调试信息（调试器要用的信息）</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; （2）调试时 需要让程序在调试器模式下运行。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;在Xcode中有两种运行程序的方法：Run-&gt;run &nbsp;(快捷键：<span style="line-height: normal; text-decoration: underline; "><strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); ">command + R</span></strong></span>)， 不用调试器运行程序；</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Run-&gt;Go(Debug)或者Run-&gt;Debug(快捷键：command+Y)，使用调试器运行程序。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; （3）对 断点 的操作</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;如何设置断点？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 在 边列（gutter）上单击 就可以设置一个蓝色的断点；在次单击就disable该断点；如果要删除该断点 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;就将该断点拖出边列。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 调试快捷键：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continue &nbsp; &nbsp;: &nbsp; &nbsp;option + command + P</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;step Into &nbsp; : &nbsp; &nbsp; shift + command + I</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;step Over : &nbsp; &nbsp; &nbsp;shift + command + O</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;step Out &nbsp; : &nbsp; &nbsp; &nbsp;shift + command + T</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;打开Xcode的调试窗口（点击调试控制栏上一个有喷雾器的方框）如下图：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 通过该窗口，可以执行各种调试命令并观察变量值的变化。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="line-height: 28px; font-size: large; "><a href="http://img.bimg.126.net/photo/hAxouRFM1uqGw6GdmdJO_g==/5643573283049852919.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/5dce5a812fe7268bbd3e1ed6.jpg" style="line-height: normal; "></a></span></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 28px; font-size: large; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 28px; font-size: large; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;如下是GDB的命令调试窗口，在其中可以输入gdb的调试命令对程序进行调试：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 28px; font-size: large; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://img.bimg.126.net/photo/MZOGCBKqLMUj2ZZImVfA9g==/5643573283049853227.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/117b2fd80dd38e6632fa1cd6.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 28px; font-size: large; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;通过调试控制栏上一个控件(黑色方框控件右边的那个),可以察看函数调用栈；如上图所示。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Note]边列(断点所在的列) 傍边较窄一列就是 焦点列。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); font-family: Arial; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">到此为止，我们大概学习了Xcode这一强大的工具，要想深入研究它，我们还有很多的路要走，不过我们已经有了一个好的开始...</span></span></p>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/141890.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2011-03-15 15:52 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/141890.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xcode 使用1</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/141889.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Tue, 15 Mar 2011 07:51:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/141889.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/141889.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/141889.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/141889.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/141889.html</trackback:ping><description><![CDATA[<table style="table-layout: fixed; font-family: Arial; font-size: 12px; line-height: 18px; width: 960px; "><tbody><tr><td style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; "><div id="blog_text" class="cnt" style="font-family: Arial; word-wrap: break-word; word-break: normal; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 20px; color: rgb(51, 51, 51); overflow-x: hidden; overflow-y: hidden; position: static; "><p style="line-height: normal; ">http://blog.163.com/lyzaily@126/blog/static/42438837200972903444447/<br style="line-height: normal; ">原文地址，方便看</p><p style="line-height: normal; ">Xcode是一个款强大的IDE开发环境，就像你在写Windows程序时需要VS2005一样 需要要Xcode为你写Mac程序提供环境。因此，如果你要成为Mac 程序的开发者，灵活运用Xcode工具是你必须做的第一步。</p><div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: normal; ">1）我们写程序时常常在源文件的头部添加copyright声明以及公司名称等等；而Xcode在创建文件时已经帮我们做了绝大部分工作，我们 可能需要修改一下公司名称，因为xcode给不知道我们公司名称，它不可能预知一切，所以需要我们自己通过设置来告诉它。那么我们如何做到这一点呢？因为 xcode中没有有关公司名称的占位符，所以我们必须通过terminal使用命令来设置。</div><div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: normal; ">在使用这个命令之前 我们来看看xcode为我们提供的默认文件头部注释：</div><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//&nbsp; untitled.m</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//&nbsp; FilesOrganize</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//&nbsp; Created by yan li on 8/29/09.</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//&nbsp; Copyright 2009&nbsp;<strong style="line-height: normal; "><span style="line-height: normal; font-size: small; ">__MyCompanyName__</span></strong>. All rights reserved.</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">//</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在terminal中执行如下命令（打开terminal的热键是<strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); "><span style="line-height: normal; text-decoration: underline; ">command+shift+U</span></span></strong>)：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "></span></span></p><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">yan-lis-macbook-pro:~ yanli$ defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "LiYanzhong";}'</p><div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: normal; "><span style="line-height: normal; "><br style="line-height: normal; "></span></div><div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: normal; ">注意上面的命令是在terminal命令行的同一行，而不是两行，这里是因为命令太长所导致。注<span style="line-height: normal; color: rgb(0, 0, 255); ">意该命令执行时不会发出任何提示，即使你在命令中写错了参数名执行后也不会有任何提示，所以如果你执行该命令后发现你期待的效果没有出现，就请你检查一下你是否有拼写错误，</span>执行该命令后我们重新启动xcode并重新创建文件，这个时候创建的文件头部注释，如下所见：</div><div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: normal; "><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">/*</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*&nbsp; untitled.h</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*&nbsp; Untitled</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*&nbsp; Created by yan li on 8/29/09.</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*&nbsp; Copyright 2009&nbsp;<strong style="line-height: normal; ">LiYanzhong</strong>. All rights reserved.</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">&nbsp;*/</p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; "><br style="line-height: normal; "></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">2）使用编辑器的技巧</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; a)如何关闭Xcode界面上的浏览器窗口？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;点击 在Xcode工具栏上的最右边个Editor图标，可以打开或关闭Xcode中查找项目文件的浏览器。<span style="line-height: normal; color: rgb(0, 0, 255); "><span style="line-height: normal; text-decoration: underline; ">快捷键是command+shift+E</span></span>。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/EFnsrisiePslPO0Fxc0rhA==/1747396655420470386.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/62af828f1bbeabbdf11f36cb.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">如果你的窗口上每个我所说的图标，则你需要自己手动将该图标放置到工具栏上。如何放呢？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">激活Xcode工具，进入 View-&gt;Customize Toolbar... &nbsp;你会发现右很多没有在工具栏上出现的工具，你可以将想要随时可以用的工具拖到工具栏上就ok了。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; b)如何对代码进行首行缩进？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; 第一种方法：选中需要缩进的代码，按住control键后单击光标，出现pop菜单，然后选择Re-indent selection。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; 第二种方法：选择需要调整的代码，同时按下<span style="line-height: normal; text-decoration: underline; "><strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); ">command＋［</span></strong></span>（左移动代码）或<strong style="line-height: normal; "><span style="line-height: normal; text-decoration: underline; "><span style="line-height: normal; color: rgb(0, 0, 255); ">command＋］</span></span></strong>（右移动代 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 码）。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp;c)代码自动完成功能的强大应用</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 在Xcode中写代码，Xcode编辑器常常给出提示，如果给出的代码提示符合我们的要求，我们就可以按tab键选择所提示的代码。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 如果提示代码不符合我们要求，我们可以按下esc键，将整个提示列表显示出来，找到我们需要的。在列表成员的最左边有个小方框，如果里面是f则对应的成员是函数；如果是m则是方法；如果是＃则是＃define命令；如果是E则是枚举；如果上C表示类。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 如果我们不希望显示提示列表也能在列表成员间选择，我们可以使用快捷键<strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); "><span style="line-height: normal; text-decoration: underline; ">control＋.&nbsp;</span></span></strong>&nbsp;在选项之间循环；也可以使用<strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); "><span style="line-height: normal; text-decoration: underline; ">shift＋control＋.</span></span></strong>&nbsp;在选项间反向循环。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 我们可以通过&#8220;代码自动完成功能&#8221;来查询一个类所提供了哪些API(接口方法）。方法是将类写在方法调用表达式中实现这一查询功能：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">［NSDictionary+空格，然后按下esc键，将出现NSDictionary中提供的方法列表。注意：[NSDictonary后面必须要有空格，提示编译器类名称已经写完接下来要输入的是消息（即类中的方法名）。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">将光标从一个占位符跳到下一个占位符的快捷键是：<strong style="line-height: normal; "><span style="line-height: normal; text-decoration: underline; "><span style="line-height: normal; color: rgb(0, 0, 255); ">control + /</span></span></strong></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">d)在修改一个项目的代码时，请先拍下快照。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; File-&gt;Make Snapshot 拍下项目的快照； File-&gt;Snapshots &nbsp;从快照中恢复。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; 对应的快捷键：control＋command＋S; &nbsp; 恢复没有快捷键</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">这样的好处就是－－当代码修改烂了，可以恢复到最处状态。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">由此可见，这个功能只是在我们修改代码时提供帮助，不能真正的替代我们手动修改代码。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">e）查找 替换功能的使用：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Edit-&gt;Find-&gt;Find in Projects...</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">出现如下对话框：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/XzaVCzfsSJs2oYCjpml_Wg==/1974546961626061946.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/1d25a2ee69f5057a2cf534cb.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在Find栏输入要查找的字符；在Replace栏中输入要替换查找到的字符的字符；我们选择在工程中查找。如果我们不选择Ignore case 则替换只发生在main()函数中。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">该方法修改代码有很到的弊端－－如果我只想修改某个函数内的car字符，但是这样修改会将函数外的所有我不许修改的car字符也改了；二是它不能修改类名和文件名；所以需要下面的方法来弥补它的第一不足。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">f)该方法可以解决上面修改代码的第一个缺陷，可以将代码的修改控制在一个函数之内，但是它仍然不能修改类和文件名字。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">使用这个方法前，<strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); ">必须用光标选择一个需要修改的局部变量字符或函数参数</span></strong>，注意必须是字符，如果你选择的是类名字符则不会出现菜单项&#8220; Edit all in Scope".</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">Edit-&gt;Edit all in Scope,然后在你输入的时候，所有出现该字符的地方一起被输入的字符替换掉。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">g)下面讲解一种可以修改类名和文件名的方法。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">&nbsp;&nbsp; &nbsp;是用该方法可以改变类名字和文件名；先选择一个需要被修改的类名，如Engine；将光标插了到该字符中，选择Edit-&gt;Refactor...打开如下的对话框：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/Fh2hEMrhYcLuTev_0SVSOg==/2034782606642049295.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/616e0c29b61fdfad98250acb.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/J3ZdT3Zk_4Ag3NwzCuq6hQ==/2034782606642048950.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/bc84d6fe04cf83625d6008cb.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">你如果需要将Car修也可以。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">按下 preview按钮，界面如下所见，Xcode自动给处了我们分析报告，有什么文件将被修改，每个文件有几处会被修改等信息。从下面图可以看到，类名以及类的文件名都被修改了。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><a href="http://img.bimg.126.net/photo/o-yTc9_2mex92teeHMAGoA==/2034782606642049406.jpg" target="_blank" style="line-height: normal; "><img title="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" alt="[原创]Xcode使用入门 - lyzaily@126 - 小坏狗的博客" src="http://hiphotos.baidu.com/kazaff/pic/item/cd1102a8ff35b2e2ca130ccb.jpg" style="line-height: normal; "></a></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">h)在Cocoa文本域常用的快捷键：</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">使用如下的快捷键 我们就可以在小范围呢移动光标二不让手不离开键盘了。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋F &nbsp;: 在同一行上将光标向右移动</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋B : 在同一行上将光标向左移动</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋P : &nbsp;将光标移动到前一行</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋N : &nbsp;将光标移动到后一行</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋A : &nbsp; 将光标移动到本行的行首</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋N : &nbsp; 将光标移动到本行的行尾</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋T : &nbsp; 将光标两边的字符对调</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋D : &nbsp; 删除光标右边的字符</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control＋k : &nbsp; 删除光标所在行 光标后面的代码，便于你重写行尾代码</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">control + L :将光标插点置于窗口正中。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">i)如何在Xcode中搜索一个文件？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在一个源文件如何打开一个由#imp<wbr style="line-height: normal; ">ort导入的头文件呢？</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">选中该头文件（可以不包含.h），然后通过File-&gt;Open Quickly...打开该被选中的文件。</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">在没有选中任何文本时，选择Open Quickly...则打开一个简单的查询窗口，查找工程中的文件。快捷键<span style="line-height: normal; text-decoration: underline; "><strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); ">command＋shift＋D</span></strong></span></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><br style="line-height: normal; "></span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; ">如果你当前在看一个.m文件，这个时候你突然想要看看与该文件对应的.h文件，我们可以使用</span></span></p><p style="line-height: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="line-height: normal; font-size: 18px; color: rgb(0, 0, 0); font-family: Arial, Verdana, Helvetica, sans-serif; "><span style="line-height: 22px; font-size: 14px; "><strong style="line-height: normal; "><span style="line-height: normal; color: rgb(0, 0, 255); "><span style="line-height: normal; text-decoration: underline; ">command + option+向上箭头</span></span></strong>&nbsp;&nbsp;组合键，打开配套文件。</span></span></p></div></span></div></td></tr></tbody></table>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/141889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2011-03-15 15:51 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/141889.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>release 时去掉nslog的方法</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/137153.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 22 Dec 2010 00:29:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/137153.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/137153.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/137153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/137153.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/137153.html</trackback:ping><description><![CDATA[<div style="background-color: rgb(238, 238, 238); font-size: 13px; border-left-color: rgb(204, 204, 204); padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000; ">#ifndef&nbsp;__OPTIMIZE__<br>#&nbsp;&nbsp;&nbsp;&nbsp;define&nbsp;NSLog(<img src="http://www.cppblog.com/Images/dot.gif">)&nbsp;NSLog(__VA_ARGS__)<br></span><span style="color: #0000FF; ">#else</span><span style="color: #000000; "><br>#&nbsp;&nbsp;&nbsp;&nbsp;define&nbsp;NSLog(<img src="http://www.cppblog.com/Images/dot.gif">)&nbsp;{}<br></span><span style="color: #0000FF; ">#endif</span></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/137153.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-12-22 08:29 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/137153.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iPhone with File I/O</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/135811.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 08 Dec 2010 07:56:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/135811.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/135811.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/135811.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/135811.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/135811.html</trackback:ping><description><![CDATA[


<p><strong><a href="http://servin.com">Servin Mobile Software</a></strong></p>

<hr>
<h1>How to use iPhone with File I/O Functions: A Tutorial for Software Developers</h1>

<hr>
<p><a href="http://servin.com/contact.php?fn=contact">Norman McEntire</a></p>
<p>Version 1.4 Sep 1. Thank you Freedy.</p>
<p>Version 1.3 Aug 6. Thank you Chris B.</p>
<p>Version 1.2 May 1. Thank you Pierre M.</p>
<p>Version 1.1 January 20</p>
<p>Copyright &#169; 2009 Servin Corporation. <a href="http://servin.com">http://servin.com</a></p>

<hr>
<h2>Introduction</h2>

<p>
The iPhone OS, like Mac OS X,
provides both Apple specific file I/O functions,
and Unix-type file I/O functions.
</p>

<p>
For example,
you can use Apple specific functions to
find the paths related to your application.
You can also use Apple specific Object-C classes to read/write files.
</p>

<p>
An alternative is to use Unix-specific functions to read/write files.
In addition to the standard open/close/read/write,
you can do memory mapping, where the file is mapped directly
into your address space.


</p><p>
In this Servin Mini-Course,
you will learn how to use Apple-specific functions and class methods
to perform file I/O.


</p><hr>
<h2>iPhone Software Skills You Will Learn</h2>

<ul>
<li>How to use Xcode to create a Window-Based App.</li>
<li>How to display text output in a UITextView control.</li>
<li>How to use <strong>NSBundle</strong> to find the resource path.</li>
<li>How to use <strong>NSString</strong> to read a file.</li>
<li>How to use <strong>NSSearchPathForDirectoriesInDomains()</strong> to find common search paths.</li>
</ul>

<hr>
<h2>Prerequisites</h2>

<ul>
<li>
You should have already setup your iPhone software development environment.
If this is not the case, then refer to the
<a href="iPhone-Flashlight-Mini-Course.html">iPhone Flashlight App: Hands-On for Software Developers</a>
</li>
</ul>

<hr>
<h2>Startup Xcode</h2>
<p>
If Xcode is not already running, start it up:
</p>
<ol>
<li>On the Mac Desktop, double-click on the Finder icon (the icon with the face on it).</li>
<li>On the left-side of the Finder window, click on <strong>Macintosh HD</strong>.</li>
<li>On the right-side of the Finder window, click on the <strong>Developer</strong> folder.</li>
<li>Click on the <strong>Applications</strong> folder.</li>
<li>Double-click on the <strong>Xcode</strong> icon.</li>
</ol>
<p>At this point, you should see the <strong>Xcode</strong> menu at the top of your desktop.</p>

<hr>
<h2>Create New Xcode Project</h2>
<p>
With <strong>Xcode</strong> running, create a new Xcode project:
</p>
<ol>
<li><strong>File &gt; New Project</strong>.</li>
<li>On the left-side of the New Project window, select <strong>Application</strong> under <strong>iPhone OS</strong>.</li>
<li>On the right-side of the New Project window, select <strong>Window-Based Application</strong>.</li>
<li>Click on the <strong>Choose</strong> button.</li>
<li>Enter <strong>FileIo</strong> for the project name.</li>
<li>Click on <strong>Save</strong> button.
</li></ol>
<p>
At this point, you should see Xcode open a new window that shows a number of files.
</p>

<hr>
<h2>Build Default App</h2>
<p>
Go ahead and build the default application:
</p>
<ol>
<li>
Click on the <strong>Build and Go</strong> button.
</li>
<li>
After a brief moment, you should see the code running in the <strong>iPhone Simulator</strong>.
</li>
<li>
Observe the status bar at the top of the window,
and a white window everywhere else.
</li>
<li>
In the iPhone Simulator, press the <strong>Home</strong> button to stop the application.
</li>
</ol>

<hr>
<h2>Edit FileIoAppDelegate to Add UITextView as Subview to UIWindow</h2>

<p>
In this exercise,
you will edit <strong>FileIoAppDelegate.h</strong> and
<strong>FileIoAppDelegate.m</strong> to add a <strong>UITextView</strong>
as a subview to the <strong>UIWindow</strong>.
</p>

<ol>

<li>
In Xcode,
in the <strong>Groups &amp; Files</strong> window on the left-side,
click on the <strong>Classes</strong> folder.
</li>

<li>
You should see the following files on the right-side of the window:
<pre>FileIoAppDelegate.h
FileIoAppDelegate.m
</pre>
</li>

<li>
Select <strong>FileIoAppDelegate.h</strong> so that it appears
in the <strong>Xcode</strong> editor window.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;UIKit/UIKit.h&gt;

@interface FileIoAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
	UIWindow *window;
<font color="red">
	UITextView *textView;
</font>
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
<font color="red">
@property (nonatomic, retain) UITextView *textView;
</font>
@end
</pre>
</li>

<li>
The above code adds a member variable named <strong>textView</strong>,
which is a pointer to an object of type <strong>UITextView</strong>.
Our goal is to use the <strong>UITextView</strong> control to
display the output.
</li>

<li>
We will not use <strong>Interface Builder</strong> for this demo,
so we did not add the <strong>IBOutlet</strong> to the code that we entered.
</li>

<li>
Select <strong>FileIoAppDelegate.m</strong> into the <strong>Xcode</strong> editor window.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
<font color="red">
@synthesize textView;
</font>

- (void)applicationDidFinishLaunching:(UIApplication *)application {
<font color="red">
	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Add text
	self.textView.text = @"Output will go here...";

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];
</font>
	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
You should see your app running,
with the text "Output will go here..." displayed in the window.
</li>

<li>
Press <strong>Home</strong> in iPhone Simulator to stop the application.
</li>

</ol>

<p>
As a review,
in this exercise you added code to the <strong>FileIoAppDelegate</strong> class to
create a  <strong>UITextView</strong>,
setting it so that it cannot be edited.
You also added text to the UITextView,
and then added the UITextView to the subview of the window.
</p>

<hr>
<h2>Create MyFile.txt</h2>

<p>
In this exercise,
you will create a file named <strong>MyFile.txt</strong> as a sample
text file that you will later read and display in the iPhone window.
</p>

<ol>

<li>
In Xcode,
in the <strong>Groups &amp; Files</strong> window on the left-side,
click on the <strong>Resources</strong> folder.
</li>

<li>
You should see the following frameworks:
<pre>- Info.plist
- MainWindow.xib
</pre>
</li>

<li>
<strong>Control+click</strong> on the <strong>Resources</strong> folder.
</li>

<li>
Select <strong>Add</strong> from the popup menu.
</li>

<li>
Select <strong>New File</strong>.
</li>

<li>
In the New File window,
on the left-side of the window,
under the category <strong>Mac OS X</strong>,
click on <strong>Other</strong>.
</li>

<li>
In the New File window,
on the right-side of the window,
click on <strong>Empty File</strong>.
</li>

<li>
Click on <strong>Next</strong>.
</li>

<li>
Name the file <strong>MyFile.txt</strong>.
</li>

<li>
Click on <strong>Finish</strong>.
</li>

<li>
Under the <strong>Resources</strong> folder,
you should now have three files:
<pre>- MainWindow.xib
- Info.plist
- MyFile.txt
</pre>
</li>

<li>
Click on <strong>MyFile.txt</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Enter the following into the file:
<pre>This is a text file.
The file will be displayed on the iPhone.
That is all for now.
</pre>
</li>

</ol>

<p>
As a review,
you created a text file named <strong>MyFile.txt</strong> in the <strong>Resources</strong>
directory of your project.
</p>


<hr>
<h2>NSHomeDirectory()</h2>

<p>
In this exercise,
you will use the <strong>NSHomeDirectory()</strong> function to retrieve the path
to the home directory of your application:
</p><pre>NSString *NSHomeDirectory(void);
</pre>
<p>&#160;</p>

<p>
An important point:
the location of your home directory is different depending on whether
you are running on the iPhone Simulator or on an actual device (iPhone or iPod Touch).
</p>


<ol>

<li>
In Xcode,
in the <strong>Groups &amp; Files</strong> window on the left-side,
click on the <strong>Classes</strong> folder.
</li>

<li>
You should see the following files:
<pre>- FileIoAppDelegate.h
- FileIoAppDelegate.m
</pre>
</li>

<li>
Click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];
<font color="red">
	NSString *homeDir = NSHomeDirectory();

	// Add text
	self.textView.text = homeDir;
</font>

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
you should see a path similar to the following displayed on the screen
(the value will change based on whether you are on the iPhone Simulator
or the iPhone device):
<pre>/Users/student/Library/Application Support/iPhone/Simulator/User/Applications/...

- OR (on an actual device) -

/var/mobile/Applications/...
</pre>
</li>
</ol>

<p>
As a review,
in this exercise you used the <strong>NSHomeDirectory()</strong> function
to find the pathname of your applications home directory.
</p>

<hr>
<h2>NSTemporaryDirectory()</h2>

<p>
In this exercise,
you will use the <strong>NSTemporaryDirectory()</strong> function to retrieve the path
to the temporary directory for use by your application.
</p><pre>NSString *NSTemporaryDirectory(void);
</pre>
<p>&#160;</p>

<p>
An important point:
the location of your temporary directory is different depending on whether
you are running on the iPhone Simulator or on an actual device (iPhone or iPod Touch).
</p>


<ol>

<li>
In Xcode,
click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Get home directory
	NSString *homeDir = NSHomeDirectory();

<font color="red">
	// Get temporary directory
	NSString *tempDir = NSTemporaryDirectory();

	// Format output
	NSString *s = 
		[NSString stringWithFormat:@"homeDir:\n"
						 @"%@\n"
						 @"tempDir:\n"
						 @"%@\n",
						homeDir,
						tempDir];		
	// Add text
	self.textView.text = s;
</font>

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
you should see output similar to the following
(the values will change based on whether you are on the iPhone Simulator
or the iPhone device):
<pre>homeDir:
/Users/student/Library/Application Support/iPhone/Simulator/User/Applications/...
tempDir:
/var/folders/7m/....

- OR (on an actual device)
/private/var/mobile/Applications/.../tmp
</pre>
</li>

</ol>

<p>
As a review,
in this exercise you used the <strong>NSTemporaryDirectory()</strong> function.
</p>


<hr>
<h2>NSSearchPathForDirectoriesInDomains()</h2>

<p>
In this exercise,
you will use the <strong>NSSearchPathForDirectoriesInDomains()</strong> function to retrieve
various paths:
</p><pre>NSArray *
NSSearchPathForDirectoriesInDomains(
	NSSearchPathDirectory directory, //NSDocumentDirectory or NSCachesDirectory
	NSSearchpathDomainMask domainMask, //NSUserDomainMask
	BOOL exppandTilde); // YES
</pre>
<p>&#160;</p>

<p>
An important point:
Although a NSArray object is returned,
you will only use the first array entry (index 0),
which will contain an NSString.
</p>

<ol>

<li>
In Xcode,
click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Get home directory
	NSString *homeDir = NSHomeDirectory();

	// Get temporary directory
	NSString *tempDir = NSTemporaryDirectory();

<font color="red">
	// Get documents directory
	NSArray *arrayPaths = 
		NSSearchPathForDirectoriesInDomains(
			NSDocumentDirectory,
			NSUserDomainMask,
			YES);

	NSString *docDir = [arrayPaths objectAtIndex:0];

	// Format output
	NSString *s = 
		[NSString stringWithFormat:@"homeDir:\n"
						 @"%@\n"
						 @"tempDir:\n"
						 @"%@\n"
						 @"docDir:\n"
						 @"%@\n",
						homeDir,
						tempDir,
						docDir];		
</font>
	// Add text
	self.textView.text = s;

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
you should see output similar to the following:
<pre>homeDir:
/Users/student/Library/Application Support/iPhone/Simulator/User/Applications/...
tempDir:
/var/folder/7m/....
docDir:
/Users/student/Library/Application Support/.../Documents
</pre>
</li>
</ol>

<p>
As a review,
in this exercise you used the <strong>NSSearchPathForDirectoriesInDomain()</strong> function.
</p>

<hr>
<h2>Using NSBundle and pathForResource:ofType:</h2>

<p>
In this exercise,
you will use the <strong>NSBundle</strong> class to
report the path to the applications resources.
The applications resources are stored in the application bundle,
and the path to this bundle can be found with the method <strong>pathForRecoure:ofType:</strong>.
</p>

<ol>

<li>
In Xcode,
click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Get home directory
	NSString *homeDir = NSHomeDirectory();

	// Get temporary directory
	NSString *tempDir = NSTemporaryDirectory();

	// Get documents directory
	NSArray *arrayPaths = 
		NSSearchPathForDirectoriesInDomains(
			NSDocumentDirectory,
			NSUserDomainMask,
			YES);

	NSString *docDir = [arrayPaths objectAtIndex:0];

<font color="red">
	NSString *myFilePath = [[NSBundle mainBundle]
				pathForResource:@"MyFile"
				ofType:@"txt"];

	// Format output
	NSString *s = 
		[NSString stringWithFormat:@"homeDir:\n"
						 @"%@\n"
						 @"tempDir:\n"
						 @"%@\n"
						 @"docDir:\n"
						 @"%@\n"
						 @"myFilePath:\n"
						 @"%@\n",
						homeDir,
						tempDir,
						docDir,
						myFilePath];		
</font>
	// Add text
	self.textView.text = s;

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
you should see output similar to the following:
<pre>homeDir:
/Users/student/Library/Application Support/iPhone/Simulator/User/Applications/...
tempDir:
/var/folder/7m/....
docDir:
/Users/student/Library/Application Support.../Documents
myFilePath:
/Users/student/Library/Application Support/.../FileIo.App/MyFile.txt
</pre>
</li>
</ol>

<p>
As a review,
in this exercise you used the <strong>NSBundle</strong> class to determine the path
to the <strong>MyFile.txt</strong>, which is stored as part of the resource bundle.
</p>

<hr>
<h2>Using NSString and stringWithContentsOfFile:encoding:error:</h2>

<p>
In this exercise,
you will use the <strong>NSString</strong> class to
read the <strong>MyText.txt</strong> file.
</p>

<ol>

<li>
In Xcode,
click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Get home directory
	NSString *homeDir = NSHomeDirectory();

	// Get temporary directory
	NSString *tempDir = NSTemporaryDirectory();

	// Get documents directory
	NSArray *arrayPaths = 
		NSSearchPathForDirectoriesInDomains(
			NSDocumentDirectory,
			NSUserDomainMask,
			YES);

	NSString docDir = [arrayPaths objectAtIndex:0];

	NSString *myFilePath = [[NSBundle mainBundle]
				pathForResource:@"MyFile"
				ofType:@"txt"];

<font color="red">
	NSString *myFileContents = [NSString stringWithContentsOfFile:myFilePath
					     encoding:NSUTF8StringEncoding
					     error:nil];

	// Format output
	NSString *s = 
		[NSString stringWithFormat:@"homeDir:\n"
						 @"%@\n"
						 @"tempDir:\n"
						 @"%@\n"
						 @"docDir:\n"
						 @"%@\n"
						 @"myFilePath:\n"
						 @"%@\n"
						 @"Contents of file:\n"
						 @"%@\n",
						homeDir,
						tempDir,
						docDir,
						myFilePath,
						myFileContents];		
</font>
	// Add text
	self.textView.text = s;

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
you should see output similar to the following:
<pre>homeDir:
/Users/student/Library/Application Support/iPhone/Simulator/User/Applications/...
tempDir:
/var/folder/7m/....
docDir:
/Users/student/Library/Application Support/.../Documents
myFilePath:
/Users/student/Library/Application Support/.../FileIo.App/MyFile.txt
Contents of file:
This is a text file.
This file will be displayed on the iPhone.
That is all for now.
</pre>
</li>
</ol>

<p>
As a review,
in this exercise you used the <strong>NSString</strong> class to
read the contents of <strong>MyFile.txt</strong>.
</p>


<hr>
<h2>Using NSString and writeFileTo:atomically:encoding:</h2>

<p>
In this exercise,
you will use the <strong>NSString</strong> class to
write a new file named <strong>NewText.txt</strong>.
</p>

<ol>

<li>
In Xcode,
click on <strong>FileIoAppDelegate.m</strong> to select it into the <strong>Xcode</strong> editor.
</li>

<li>
Edit the code to match the following:
<pre>#import &lt;FileIoAppDelegate.h&gt;

@implementation FileIoAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	// Create instance of UITextView
	self.textView = [[UITextView alloc] 
			 initWithFrame:[[UIScreen mainScreen] applicationFrame]];

	// Get home directory
	NSString *homeDir = NSHomeDirectory();

	// Get temporary directory
	NSString *tempDir = NSTemporaryDirectory();

	// Get documents directory
	NSArray *arrayPaths = 
		NSSearchPathForDirectoriesInDomains(
			NSDocumentDirectory,
			NSUserDomainMask,
			YES);

	NSString docDir = [arrayPaths objectAtIndex:0];

	NSString *myFilePath = [[NSBundle mainBundle]
				pathForResource:@"MyFile"
				ofType:@"txt"];

	NSString *myFileContents = [NSString stringWithContentsOfFile:myFilePath
					     encoding:NSUTF8StringEncoding
					     error:nil];

	// Format output
	NSString *s = 
		[NSString stringWithFormat:@"homeDir:\n"
						 @"%@\n"
						 @"tempDir:\n"
						 @"%@\n"
						 @"docDir:\n"
						 @"%@\n"
						 @"myFilePath:\n"
						 @"%@\n"
						 @"Contents of file:\n"
						 @"%@\n",
						homeDir,
						tempDir,
						docDir,
						myFilePath,
						myFileContents];		
<font color="red">
	// Create pathname to Documents directory
	NSString *newFilePath = [docDir stringByAppendingString:@"/NewFile.txt"];

	// Write string to file
	[s writeToFile:newFilePath
	   atomically:YES
	   encoding:NSUTF8StringEncoding
	   error:nil];
</font>
	// Add text
	self.textView.text = s;

	// Make non-editable
	self.textView.editable = NO;

	// Add as subview to window
	[window addSubview:self.textView];

	// Decrement our usage count
	[self.textView release];

	[window makeKeyAndVisible];
}
</pre>
</li>

<li>
<strong>Build and Go</strong>.
</li>

<li>
When your application runs,
it displays output on the iPhone screen,
and also writes the output to the <strong>NewFile.txt</strong> file.
</li>

<li>
While the iPhone Simulator is still running,
open up a terminal window,
and <strong>cat</strong> (concatenate) out the contents
of the file:
<pre>$ cat /Users/student/Library/Application Support/.../Documents/NewFile.txt
...
</pre>
</li>
</ol>

<p>
As a review,
in this exercise you used the <strong>NSString</strong> class to
write the contents of a NSString <strong>MyFile.txt</strong>.
</p>



<hr>
<h2>Skills Review</h2>
<ul>

<li>Xcode</li>
<li>Window-Based Application</li>
<li>UITextView</li>

<li>NSHomeDirectory()</li>
<li>NSTemporaryDirectory()</li>
<li>NSSearchPathForDirectoriesInDomains()</li>

<li>NSBundle</li>
<li>mainBundle</li>
<li>pathForResource:ofType:</li>

<li>NSString</li>
<li>stringWithContentsOfFile:encoding:error:</li>
<li>writeToFile:atomically:encoding:error:</li>

</ul>

<hr>
<h2>How To Contact Author</h2>
<p>
Feel free to <a href="http://servin.com/contact.php?fn=contact&amp;sub=jan20">contact the author</a>
for any of the following:
</p>
<ul>
<li>You have a question or comment about this mini-course.</li>
<li>You need to hire Servin to help with your software development project.</li>
<li>You need to hire Servin to give an on-site training course for your software development team.</li>
</ul>

<hr>
<p>
<small>
Updated 2009 Sep 1<br>
Content viewable on all web browsers, including smart mobile phone devices.<br>
Copyright &#169; 1995-2009 Servin Corporation. All rights reserved.
</small>
</p>



<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/135811.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-12-08 15:56 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/135811.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>图像处理小结</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/125812.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Fri, 03 Sep 2010 09:23:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/125812.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/125812.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/125812.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/125812.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/125812.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'; color: #4300d7">1.</span>将一个指定的图形放大或缩小为指定的尺寸<span style="font: 14.0px 'Heiti SC Light'">，</span>可以试试以下代码</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(UIImage*)scaleToSize:(UIImage*)img<span style="font: 14.0px 'GB18030 Bitmap'"> </span>size:(CGSize)size<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'">{</span> &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #048706"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp; &nbsp; </span>//<span style="font: 14.0px 'GB18030 Bitmap'"> 创建一个</span>bitmap<span style="font: 14.0px 'GB18030 Bitmap'">的</span>context<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #048706"><span style="color: #000000">&nbsp; &nbsp; </span><span style="font: 14.0px 'Lucida Grande'">//</span> 并把它设置成为当前正在使用的<span style="font: 14.0px 'Lucida Grande'">context</span> &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>UIGraphicsBeginImageContext(size);<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #048706"><span style="color: #000000">&nbsp; &nbsp; </span><span style="font: 14.0px 'Lucida Grande'">//</span> 绘制改变大小的图片 &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[img<span style="font: 14.0px 'GB18030 Bitmap'"> </span>drawInRect:CGRectMake(<span style="color: #4300d7">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4300d7">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>size.width,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>size.height)];<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #048706"><span style="color: #000000">&nbsp; &nbsp; </span><span style="font: 14.0px 'Lucida Grande'">//</span> 从当前<span style="font: 14.0px 'Lucida Grande'">context</span>中创建一个改变大小后的图片 &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>UIImage*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>scaledImage<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIGraphicsGetImageFromCurrentImageContext();<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #048706"><span style="color: #000000">&nbsp; &nbsp; </span><span style="font: 14.0px 'Lucida Grande'">//</span> 使当前的<span style="font: 14.0px 'Lucida Grande'">context</span>出堆栈 &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>UIGraphicsEndImageContext();<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #048706"><span style="color: #000000">&nbsp; &nbsp; </span><span style="font: 14.0px 'Lucida Grande'">//</span> 返回新的改变大小后的图片 &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b719a2">return</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>scaledImage;<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4300d7">2.</span><span style="font: 14.0px 'GB18030 Bitmap'">图片如何存入 </span>iPhone<span style="font: 14.0px 'GB18030 Bitmap'"> 本地 </span>Documents<span style="font: 14.0px 'GB18030 Bitmap'"> 的方法</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">在 <span style="font: 14.0px 'Lucida Grande'">UIButton</span> 的 <span style="font: 14.0px 'Lucida Grande'">saveImage</span> 方法里添加一张图片<span style="font: 14.0px 'Heiti SC Light'">，</span>以下代码可将图片存入本地的 <span style="font: 14.0px 'Lucida Grande'">Documents</span> 下<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b719a2">void</span>)saveImage</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>NSANSArray<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*paths<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">YES</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*documentsDirectory<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[paths<span style="font: 14.0px 'GB18030 Bitmap'"> </span>objectAtIndex:<span style="color: #4300d7">0</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*savedImagePath<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[documentsDirectory<span style="font: 14.0px 'GB18030 Bitmap'"> </span>stringByAppendingPathComponent:<span style="color: #c9331c">@"savedImage.png"</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #048706"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp; &nbsp; </span>//also<span style="font: 14.0px 'GB18030 Bitmap'"> </span>be<span style="font: 14.0px 'GB18030 Bitmap'"> </span>.jpg<span style="font: 14.0px 'GB18030 Bitmap'"> </span>or<span style="font: 14.0px 'GB18030 Bitmap'"> </span>another</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>UIImage<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*image<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>imageView.image;<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #048706">//</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> </span><span style="color: #048706">imageView</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> </span><span style="color: #048706">is</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> </span><span style="color: #048706">your</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> </span><span style="color: #048706">image</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #048706"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp; &nbsp; </span>//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Returns<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>data<span style="font: 14.0px 'GB18030 Bitmap'"> </span>for<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>specified<span style="font: 14.0px 'GB18030 Bitmap'"> </span>image<span style="font: 14.0px 'GB18030 Bitmap'"> </span>in<span style="font: 14.0px 'GB18030 Bitmap'"> </span>JPEG/PNG<span style="font: 14.0px 'GB18030 Bitmap'"> </span>format.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>NSData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*imageData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIImagePNGRepresentation(image);<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #048706">//UIImageJPEGRepresentation(image)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[imageData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>writeToFile:savedImagePath<span style="font: 14.0px 'GB18030 Bitmap'"> </span>atomically:<span style="color: #b719a2">NO</span>];<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4300d7">3.</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIImageWriteToSavedPhotosAlbum<span style="font: 14.0px 'GB18030 Bitmap'">保存图片的方法</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">用</span>UIImageWriteToSavedPhotosAlbum<span style="font: 14.0px 'GB18030 Bitmap'">往照片库里面存图片时</span><span style="font: 14.0px 'Heiti SC Light'">，</span><span style="font: 14.0px 'GB18030 Bitmap'">经常发生缩略图能看到但原图消失的问题</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">用 </span>UIImageWriteToSavedPhotosAlbum(imageSave,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">nil</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">nil</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">nil</span>),<span style="font: 14.0px 'GB18030 Bitmap'"> </span>imageSave<span style="font: 14.0px 'GB18030 Bitmap'">是</span>UIImage<span style="font: 14.0px 'GB18030 Bitmap'">类型</span><span style="font: 14.0px 'Heiti SC Light'">，</span><span style="font: 14.0px 'GB18030 Bitmap'">这样就保存进去了</span><span style="font: 14.0px 'Heiti SC Light'">。</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">而且注意图片不宜过大<span style="font: 14.0px 'Heiti SC Light'">，</span>以免程序崩溃</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'; color: #4300d7">4.</span>保存已选取的图片<span style="font: 14.0px 'Heiti SC Light'">，</span>下次启动<span style="font: 14.0px 'Lucida Grande'">App</span>时直接显示的方</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">如果您想在<span style="font: 14.0px 'Lucida Grande'">iPhone</span> <span style="font: 14.0px 'Lucida Grande'">App</span>里实现保存一张图片<span style="font: 14.0px 'Heiti SC Light'">，</span>下次再启动该<span style="font: 14.0px 'Lucida Grande'">App</span>时直接自动显示该图的功能<span style="font: 14.0px 'Heiti SC Light'">，</span>可以使用以下方法</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">NSData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*imageData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIImageJPEGRepresentation(image,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4300d7">1.0</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">[NSData<span style="font: 14.0px 'GB18030 Bitmap'"> </span>writeToFile:<span style="font: 14.0px 'GB18030 Bitmap'"> </span>imagePath<span style="font: 14.0px 'GB18030 Bitmap'"> </span>atomically:<span style="color: #b719a2">YES</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">保存起来<span style="font: 14.0px 'Heiti SC Light'">，</span>启动时再读出就<span style="font: 14.0px 'Lucida Grande'">OK</span>了</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImage<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*_image<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[UIImage<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alloc]initWithContentsOfFile:<span style="font: 14.0px 'GB18030 Bitmap'"> </span>imagePath];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'; color: #4300d7">5.</span>在以图片为背景的<span style="font: 14.0px 'Lucida Grande'">view</span>上直接写文字</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b719a2">void</span>)drawAtPoint:(CGPoint)point<span style="font: 14.0px 'GB18030 Bitmap'"> </span>withFont:(UIFont*)font<span style="font: 14.0px 'GB18030 Bitmap'"> </span>orientation:(WBOrientation)orient;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(CGPoint)drawInRect:(CGRect)rect<span style="font: 14.0px 'GB18030 Bitmap'"> </span>withFont:(UIFont*)font<span style="font: 14.0px 'GB18030 Bitmap'"> </span>orientation:(WBOrientation)orient<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alignment:(UITextAlignment)align;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIFont<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>font<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[UIFont<span style="font: 14.0px 'GB18030 Bitmap'"> </span>fontWithName:<span style="color: #c9331c">@"Arial"</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>size:<span style="color: #4300d7">18</span>];<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*str<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #c9331c">@"Hello</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #c9331c"> </span><span style="color: #c9331c">World"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">[str<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; </span>drawAtPoint:CGPointMake(<span style="color: #4300d7">0</span>,<span style="color: #4300d7">70</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>withFont:font];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'; color: #4300d7">6.</span>从 <span style="font: 14.0px 'Lucida Grande'">iPhone/iPad</span> 图片库中读取图片的代码</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">如果您的<span style="font: 14.0px 'Lucida Grande'">App</span>涉及到从<span style="font: 14.0px 'Lucida Grande'">iPhone/iPad</span>图片库读取图片<span style="font: 14.0px 'Heiti SC Light'">，</span>不妨看看<span style="font: 14.0px 'Lucida Grande'">CocoaChina</span>版主<span style="font: 14.0px 'Lucida Grande'">&#8220;angellixf&#8221;</span>分享的代码<span style="font: 14.0px 'Heiti SC Light'">，</span>会为您节省很多时间<span style="font: 14.0px 'Heiti SC Light'">。</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImagePickerController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>picker<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[UIImagePickerController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alloc]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>init];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">picker.delegate<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">self</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">picker.sourceType<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIImagePickerControllerSourceTypePhotoLibrary;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">[<span style="color: #b719a2">self</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>presentModalViewController:picker<span style="font: 14.0px 'GB18030 Bitmap'"> </span>animated:<span style="color: #b719a2">YES</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImagePickerControllerSourceTypePhotoLibrary,<span style="color: #048706">//</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> 相片库</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImagePickerControllerSourceTypeCamera<span style="color: #048706">//</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706">相机获取图片</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImagePickerControllerSourceTypeSavedPhotosAlbum<span style="color: #048706">//</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706"> 这个是自定义库</span><span style="font: 14.0px 'Heiti SC Light'; color: #048706">，</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #048706">是由用户截图或保存到里面的</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">将图片保存到相片库的代码<span style="font: 14.0px 'Heiti SC Light'">：</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UIImageWriteToSavedPhotosAlbum(Image,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">self</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">@selector</span>(image:didFinishSavingWithError:contextInfo:),<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b719a2">nil</span>);</p><div><br></div>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/125812.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-09-03 17:23 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/125812.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Objective-C Singleton</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123888.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 18 Aug 2010 14:25:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123888.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123888.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123888.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123888.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123888.html</trackback:ping><description><![CDATA[<p>Below is a template for the singletons that we use in objective-c.</p>
<p>MySingleton.h:</p>
<div class=wp_syntax style="PADDING-BOTTOM: 0px">
<div class=code>
<pre class=objc style="FONT-FAMILY: monospace"><span style="COLOR: #6e371a">#import &lt;Foundation/Foundation.h&gt;</span>
&nbsp;
<span style="COLOR: #a61390">@interface</span> MySingleton <span style="COLOR: #002200">:</span> <span style="COLOR: #400080">NSObject</span> <span style="COLOR: #002200">{</span>
&nbsp;
<span style="COLOR: #002200">}</span>
<span style="COLOR: #002200">+</span><span style="COLOR: #002200">(</span>MySingleton<span style="COLOR: #002200">*</span><span style="COLOR: #002200">)</span>sharedMySingleton;
<span style="COLOR: #002200">-</span><span style="COLOR: #002200">(</span><span style="COLOR: #a61390">void</span><span style="COLOR: #002200">)</span>sayHello;
<span style="COLOR: #a61390">@end</span></pre>
</div>
</div>
<p>MySingleton.m:</p>
<div class=wp_syntax style="PADDING-BOTTOM: 15px">
<div class=code>
<pre class=objc style="FONT-FAMILY: monospace"><span style="COLOR: #a61390">@implementation</span> MySingleton
<span style="COLOR: #a61390">static</span> MySingleton<span style="COLOR: #002200">*</span> _sharedMySingleton <span style="COLOR: #002200">=</span> <span style="COLOR: #a61390">nil</span>;
&nbsp;
<span style="COLOR: #002200">+</span><span style="COLOR: #002200">(</span>MySingleton<span style="COLOR: #002200">*</span><span style="COLOR: #002200">)</span>sharedMySingleton
<span style="COLOR: #002200">{</span>
<span style="COLOR: #a61390">@synchronized</span><span style="COLOR: #002200">(</span><span style="COLOR: #002200">[</span>MySingleton class<span style="COLOR: #002200">]</span><span style="COLOR: #002200">)</span>
<span style="COLOR: #002200">{</span>
<span style="COLOR: #a61390">if</span> <span style="COLOR: #002200">(</span><span style="COLOR: #002200">!</span>_sharedMySingleton<span style="COLOR: #002200">)</span>
<span style="COLOR: #002200">[</span><span style="COLOR: #002200">[</span>self alloc<span style="COLOR: #002200">]</span> init<span style="COLOR: #002200">]</span>;
&nbsp;
<span style="COLOR: #a61390">return</span> _sharedMySingleton;
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #a61390">return</span> <span style="COLOR: #a61390">nil</span>;
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #002200">+</span><span style="COLOR: #002200">(</span><span style="COLOR: #a61390">id</span><span style="COLOR: #002200">)</span>alloc
<span style="COLOR: #002200">{</span>
<span style="COLOR: #a61390">@synchronized</span><span style="COLOR: #002200">(</span><span style="COLOR: #002200">[</span>MySingleton class<span style="COLOR: #002200">]</span><span style="COLOR: #002200">)</span>
<span style="COLOR: #002200">{</span>
NSAssert<span style="COLOR: #002200">(</span>_sharedMySingleton <span style="COLOR: #002200">==</span> <span style="COLOR: #a61390">nil</span>, <span style="COLOR: #bf1d1a">@</span><span style="COLOR: #bf1d1a">"Attempted to allocate a second instance of a singleton."</span><span style="COLOR: #002200">)</span>;
_sharedMySingleton <span style="COLOR: #002200">=</span> <span style="COLOR: #002200">[</span>super alloc<span style="COLOR: #002200">]</span>;
<span style="COLOR: #a61390">return</span> _sharedMySingleton;
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #a61390">return</span> <span style="COLOR: #a61390">nil</span>;
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #002200">-</span><span style="COLOR: #002200">(</span><span style="COLOR: #a61390">id</span><span style="COLOR: #002200">)</span>init <span style="COLOR: #002200">{</span>
self <span style="COLOR: #002200">=</span> <span style="COLOR: #002200">[</span>super init<span style="COLOR: #002200">]</span>;
<span style="COLOR: #a61390">if</span> <span style="COLOR: #002200">(</span>self <span style="COLOR: #002200">!=</span> <span style="COLOR: #a61390">nil</span><span style="COLOR: #002200">)</span> <span style="COLOR: #002200">{</span>
<span style="COLOR: #11740a; FONT-STYLE: italic">// initialize stuff here</span>
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #a61390">return</span> self;
<span style="COLOR: #002200">}</span>
&nbsp;
<span style="COLOR: #002200">-</span><span style="COLOR: #002200">(</span><span style="COLOR: #a61390">void</span><span style="COLOR: #002200">)</span>sayHello <span style="COLOR: #002200">{</span>
NSLog<span style="COLOR: #002200">(</span><span style="COLOR: #bf1d1a">@</span><span style="COLOR: #bf1d1a">"Hello World!"</span><span style="COLOR: #002200">)</span>;
<span style="COLOR: #002200">}</span>
<span style="COLOR: #a61390">@end</span></pre>
</div>
</div>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123888.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-18 22:25 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123888.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>常用小问题</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123843.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 18 Aug 2010 08:21:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123843.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123843.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123843.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123843.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123843.html</trackback:ping><description><![CDATA[
<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><span style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; ">1.获得资源文件路径:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)pathForResource:(NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)name<span style="font: 14.0px 'GB18030 Bitmap'"> </span>ofType:(NSString<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)extension</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #7522aa">NSString</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">*path=[[</span><span style="color: #7522aa">NSBundle</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>mainBundle<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>pathForResource<span style="color: #000000">:@"bk"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;</span>ofType<span style="color: #000000">:</span><span style="color: #cb2625">@"png"</span><span style="color: #000000">];</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">2.得到应用程序代理:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">[[</span><span style="color: #7522aa">UIApplication</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>sharedApplication<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">delegate];</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">3.应用程序大小:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">[[UIScreen mainScreen] applicationFrame];</span></p><p>&#160;</p></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123843.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-18 16:21 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123843.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ViewController问题小结</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123822.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 18 Aug 2010 05:50:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123822.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123822.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123822.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123822.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123822.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4500d8">1.</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>UIViewController:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要属性<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">view</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">title</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">interfaceOrientation</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">tabBarController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">tabBarItem</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">navigationController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">navigationItem</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">parentViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要方法<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewDidLoad</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewDidUnload</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewWillAppear</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewWIllDisappear</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">presentModalViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">dismissModalViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">initWithNibName</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4500d8">2.</span>UITabBarItem:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要方法<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #b900a3">id</span>)initWithTabBarSystemItem:(<span style="color: #7522aa">UITabBarSystemItem</span>)systemItem<span style="font: 14.0px 'GB18030 Bitmap'"> </span>tag:(<span style="color: #7522aa">NSInteger</span>)tag</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #b900a3">id</span>)initWithTitle:(<span style="color: #7522aa">NSString</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)title<span style="font: 14.0px 'GB18030 Bitmap'"> </span>image:(<span style="color: #7522aa">UIImage</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)image<span style="font: 14.0px 'GB18030 Bitmap'"> </span>tag:(<span style="color: #7522aa">NSInteger</span>)tag</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4500d8">3.</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>UITabBarController:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要属性<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">delegate</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewControllers</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">selectedIndex</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">selectedViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要方法<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">setViewControllers</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">代理<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UITabBarControllerDelegate:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">tabBarController:didSelectViewController:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">tabBarController:shouldSelectViewController:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #4500d8">4.</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>UINavigationController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要属性<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">delegate</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">navigationBar</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">viewControllers</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">topViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">visibleViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">重要方法<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">initWithRootViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">pushViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">popViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">popToViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">popToRootViewController</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">setViewControllers</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">代理<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UINavigationControllerDelegate:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">navigationController:didShowViewController:animated:</p>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-18 13:50 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>表视图使用</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123600.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 16 Aug 2010 06:53:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123600.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123600.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123600.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123600.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123600.html</trackback:ping><description><![CDATA[1.表视图的代理方法如下:<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">#pragma<span style="font: 14.0px 'GB18030 Bitmap'"> </span>mark<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Table<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view<span style="font: 14.0px 'GB18030 Bitmap'"> </span>methods</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">//有多少个分区</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #7522aa">NSInteger</span>)numberOfSectionsInTableView:(<span style="color: #7522aa">UITableView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)tableView</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"> </span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b900a3">return</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); "><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); ">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Customize<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>number<span style="font: 14.0px 'GB18030 Bitmap'"> </span>of<span style="font: 14.0px 'GB18030 Bitmap'"> </span>rows<span style="font: 14.0px 'GB18030 Bitmap'"> </span>in<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>table<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view. &nbsp; 每一个分区有多少行. section为分区编号</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #7522aa">NSInteger</span>)tableView:(<span style="color: #7522aa">UITableView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)tableView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>numberOfRowsInSection:(<span style="color: #7522aa">NSInteger</span>)section</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"> </span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b900a3">return</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); "><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); ">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Customize<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>appearance<span style="font: 14.0px 'GB18030 Bitmap'"> </span>of<span style="font: 14.0px 'GB18030 Bitmap'"> </span>table<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view<span style="font: 14.0px 'GB18030 Bitmap'"> </span>cells. &nbsp;当要显示每一行时被调用.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #7522aa">UITableViewCell</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)tableView:(<span style="color: #7522aa">UITableView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)tableView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>cellForRowAtIndexPath:(<span style="color: #7522aa">NSIndexPath</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)indexPath<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"></span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; "><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</span><span style="color: #b900a3">static</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #7522aa">NSString</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*CellIdentifier<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #cb2625">@"Cell"</span>;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; "><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</span><span style="color: #7522aa">UITableViewCell</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*cell<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[tableView<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">dequeueReusableCellWithIdentifier</span>:CellIdentifier];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b900a3">if</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>(cell<span style="font: 14.0px 'GB18030 Bitmap'"> </span>==<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">nil</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #000000">cell</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">=</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">[[[</span><span style="color: #7522aa">UITableViewCell</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>alloc<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>initWithStyle<span style="color: #000000">:</span>UITableViewCellStyleDefault<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>reuseIdentifier<span style="color: #000000">:CellIdentifier]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>autorelease<span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; <span style="font: 14.0px 'Lucida Grande'">}</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;<span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); ">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Configure<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>cell.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b900a3">return</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>cell;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Override<span style="font: 14.0px 'GB18030 Bitmap'"> </span>to<span style="font: 14.0px 'GB18030 Bitmap'"> </span>support<span style="font: 14.0px 'GB18030 Bitmap'"> </span>row<span style="font: 14.0px 'GB18030 Bitmap'"> </span>selection<span style="font: 14.0px 'GB18030 Bitmap'"> </span>in<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>table<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 当有一行被选中时被调用.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #b900a3">void</span>)tableView:(<span style="color: #7522aa">UITableView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)tableView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>didSelectRowAtIndexPath:(<span style="color: #7522aa">NSIndexPath</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)indexPath<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"></span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); "><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp; &nbsp;</span>//&nbsp;Navigation<span style="font: 14.0px 'GB18030 Bitmap'"> </span>logic<span style="font: 14.0px 'GB18030 Bitmap'"> </span>may<span style="font: 14.0px 'GB18030 Bitmap'"> </span>go<span style="font: 14.0px 'GB18030 Bitmap'"> </span>here<span style="font: 14.0px 'GB18030 Bitmap'"> </span>--<span style="font: 14.0px 'GB18030 Bitmap'"> </span>for<span style="font: 14.0px 'GB18030 Bitmap'"> </span>example,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>create<span style="font: 14.0px 'GB18030 Bitmap'"> </span>and<span style="font: 14.0px 'GB18030 Bitmap'"> </span>push<span style="font: 14.0px 'GB18030 Bitmap'"> </span>another<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view<span style="font: 14.0px 'GB18030 Bitmap'"> </span>controller.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><font  color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>//&nbsp;AnotherViewController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*anotherViewController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[AnotherViewController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alloc]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>initWithNibName:@"AnotherView"<span style="font: 14.0px 'GB18030 Bitmap'"> </span>bundle:nil];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><font  color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>//&nbsp;[self.navigationController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>pushViewController:anotherViewController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>animated:YES];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><font  color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>//&nbsp;[anotherViewController<span style="font: 14.0px 'GB18030 Bitmap'"> </span>release];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p></p></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123600.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-16 14:53 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123600.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>动画的使用</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123585.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 16 Aug 2010 03:51:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123585.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123585.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123585.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123585.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123585.html</trackback:ping><description><![CDATA[1.使用UIView类函数实现:<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp;</font>[</span><span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>beginAnimations<span style="color: #000000">:</span><span style="color: #cb2625">@"animationID"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>context<span style="color: #000000">:</span><span style="color: #b900a3">nil</span><span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp;</font>[UIView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>setAnimationDuration:<span style="color: #4500d8">0.5f</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp;</font>[</span><span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>setAnimationCurve<span style="color: #000000">:</span>UIViewAnimationCurveEaseInOut<span style="color: #000000">];</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;[UIView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>setAnimationTransition: UIViewAnimationTransitionFlipFromLeft<span style="font: 14.0px 'GB18030 Bitmap'"> </span>forView:<span style="color: #b900a3">self</span>.view<span style="font: 14.0px 'GB18030 Bitmap'"> </span>cache:<span style="color: #b900a3">YES</span>];</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;<span  style="color: rgb(68, 0, 129); "><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp;//</span>UIViewAnimationTransitionFlipFromLeft<span style="color: #000000">,</span></span></p></span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp; &nbsp;//</span>UIViewAnimationTransitionFlipFromRight<span style="color: #000000">,</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp; &nbsp;//</span>UIViewAnimationTransitionCurlUp<span style="color: #000000">,</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp; &nbsp;//</span>UIViewAnimationTransitionCurlDown<span style="color: #000000">,</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">&nbsp;&nbsp; &nbsp; &nbsp; //要执行的动作.</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;</span>[UIView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>commitAnimations];</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081">2.使用<span  style="color: rgb(117, 34, 170); ">CATransition对象来实现: //公开的API</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span  style="color: rgb(117, 34, 170); "><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #7522aa"><font  color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>CATransition<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">*animation</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">=</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">[</span>CATransition<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">animation</span><span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>animation.duration<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0.5f</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>animation.timingFunction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">UIViewAnimationCurveEaseInOut</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.fillMode<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #7522aa">kCAFillModeForwards</span>;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #000000"><font  face="'GB18030 Bitmap'"><br></font></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #000000"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.</span>type<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">=</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>kCATransitionPush<span style="color: #000000">;//</span>kCATransitionMoveIn&nbsp;kCATransitionReveal&nbsp;kCATransitionFade</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #000000"></span><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.subtype<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #7522aa">kCATransitionFromLeft</span>;//kCATransitionFromRight&nbsp;kCATransitionFromTop&nbsp;&nbsp;kCATransitionFromBottom</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #7522aa"><font  color="#000000" face="'GB18030 Bitmap'"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp; &nbsp;&nbsp;[<span style="color: #b900a3">self</span>.view.layer<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addAnimation</span>:animation<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">forKey</span>:<span style="color: #cb2625">@"animation"</span>];</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">3.<span  style="color: rgb(68, 0, 129); ">2.使用<span  style="color: rgb(117, 34, 170); ">CATransition对象来实现: //末公开的API</span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span  style="color: rgb(68, 0, 129); "><span  style="color: rgb(117, 34, 170); "><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #7522aa"><font  color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>CATransition<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">*animation</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">=</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">[</span>CATransition<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">animation</span><span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>animation.delegate<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">self</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>animation.duration<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0.5f</span><span style="font: 14.0px 'GB18030 Bitmap'">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>animation.timingFunction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">UIViewAnimationCurveEaseInOut</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.fillMode<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #7522aa">kCAFillModeForwards</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.endProgress<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=1.0;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>animation.removedOnCompletion<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">NO</span>;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;<span  style="font-family: 'Lucida Grande'; ">animation.<span style="color: rgb(117, 34, 170); ">type</span><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">&nbsp;</span>=<span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">&nbsp;</span><span style="color: rgb(203, 38, 37); ">@"cube"</span>;</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; "><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;&nbsp; &nbsp;//</span><span  style="font-family: 'Lucida Grande'; "><span style="color: rgb(203, 38, 37); ">@"suckEffect"</span>;</span><span  style="color: rgb(0, 138, 0); font-family: 'Lucida Grande'; "><span style="color: rgb(203, 38, 37); ">@"oglFlip"</span><span style="color: rgb(0, 0, 0); ">;</span></span><span  style="font-family: 'Lucida Grande'; "><span style="color: rgb(203, 38, 37); ">@"rippleEffect"</span>;</span><span  style="font-family: 'Lucida Grande'; "><span style="color: rgb(203, 38, 37); ">@"pageCurl"</span>;</span><span  style="font-family: 'Lucida Grande'; "><span style="color: rgb(203, 38, 37); ">@"pageUnCurl"</span>;</span><span  style="color: rgb(203, 38, 37); font-family: 'Lucida Grande'; ">@"cameraIrisHollowOpen"<span style="color: rgb(0, 0, 0); ">;</span></span><span  style="color: rgb(203, 38, 37); font-family: 'Lucida Grande'; ">@"cameraIrisHollowClose"<span style="color: rgb(0, 0, 0); ">;</span></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre"><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font  face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;</font>[<span style="color: #b900a3">self</span>.view.layer<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addAnimation</span>:animation<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">forKey</span>:<span style="color: #cb2625">@"animation"</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p><div><span class="Apple-tab-span" style="white-space:pre"><br></span></div></span></span></p></font></p></p></span></p></p></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123585.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-16 11:51 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123585.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UINavigationVIewController的使用</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123581.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 16 Aug 2010 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123581.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123581.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123581.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123581.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123581.html</trackback:ping><description><![CDATA[
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//UINavigationController<span style="font: 14.0px 'GB18030 Bitmap'">使用方法</span>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//1.<span style="font: 14.0px 'GB18030 Bitmap'">初始化</span>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//<span style="font: 14.0px 'GB18030 Bitmap'">使用时需要一个图控制器来做为</span>UINavigationController<span style="font: 14.0px 'GB18030 Bitmap'">根视视图控制器,本例中为TestViewController:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #7522aa">UINavigationController<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">*nav</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">=</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">[[</span>UINavigationController<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">alloc</span><span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">initWithRootViewController</span><span style="color: #000000">:[[</span><span style="color: #548187">TestViewController</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">alloc</span><span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">init</span><span style="color: #000000">]];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">[window<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addSubview</span>:nav.<span style="color: #440081">view</span>];</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">#define<span style="font: 14.0px 'GB18030 Bitmap'"> </span>COOKBOOK_PURPLE_COLOR<span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[UIColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>colorWithRed:<span style="color: #4500d8">0.20392f</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>green:<span style="color: #4500d8">0.19607f</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>blue:<span style="color: #4500d8">0.61176f</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>alpha:<span style="color: #4500d8">1.0f</span>]</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">#define<span style="font: 14.0px 'GB18030 Bitmap'"> </span>BARBUTTON(TITLE,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SELECTOR)<span style="font: 14.0px 'GB18030 Bitmap'"> <span class="Apple-tab-span" style="white-space:pre">	</span></span>[[[UIBarButtonItem<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alloc]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>initWithTitle:TITLE<span style="font: 14.0px 'GB18030 Bitmap'"> </span>style:UIBarButtonItemStylePlain<span style="font: 14.0px 'GB18030 Bitmap'"> </span>target:self<span style="font: 14.0px 'GB18030 Bitmap'"> </span>action:SELECTOR]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>autorelease]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); ">//<span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">若一个视图控制器在栈中</span>,<span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">则可以调用</span>navigationController<span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">和</span>navigationItem<span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">来获得导航控制器或项目</span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; "><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; "><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; "><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; "><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); ">//2.<span style="font: 14.0px 'GB18030 Bitmap'">在</span>TestViewController<span style="font: 14.0px 'GB18030 Bitmap'">的</span>viewDidLoad<span style="font: 14.0px 'GB18030 Bitmap'">函数中</span>,<span style="font: 14.0px 'GB18030 Bitmap'">可以对导航条属性进行设置</span>:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c"><span style="color: rgb(0, 138, 0); "></span><span style="color: rgb(0, 0, 0); "><span style="color: #b900a3">self</span>.navigationController.navigationBar.tintColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=&nbsp;<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;</span><span style="color: rgb(117, 74, 44); ">COOKBOOK_PURPLE_COLOR</span>;</span></p><p>&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">self</span>.navigationItem.rightBarButtonItem<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=&nbsp;<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;</span><span style="color: rgb(117, 74, 44); ">BARBUTTON</span>(<span style="color: #cb2625">@"Flip"</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">@selector</span>(flip:));</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>Set<span style="font: 14.0px 'GB18030 Bitmap'"> </span>up<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>segmented<span style="font: 14.0px 'GB18030 Bitmap'"> </span>control<span style="font: 14.0px 'GB18030 Bitmap'"> </span>for<span style="font: 14.0px 'GB18030 Bitmap'"> </span>picking<span style="font: 14.0px 'GB18030 Bitmap'"> </span>the<span style="font: 14.0px 'GB18030 Bitmap'"> </span>animation<span style="font: 14.0px 'GB18030 Bitmap'"> </span>direction</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">UISegmentedControl<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*seg<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[[UISegmentedControl<span style="font: 14.0px 'GB18030 Bitmap'"> </span>alloc]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>initWithItems:[<span style="color: #cb2625">@"Left</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #cb2625"> </span><span style="color: #cb2625">Right"</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>componentsSeparatedByString:<span style="color: #cb2625">@"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #cb2625"> </span><span style="color: #cb2625">"</span>]]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>autorelease];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">seg.selectedSegmentIndex<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">seg.segmentedControlStyle<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>UISegmentedControlStyleBar;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">self</span>.navigationItem.titleView<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>seg;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"></p><div><span style="font: 14.0px 'GB18030 Bitmap'"><font color="#008A00" face="'Lucida Grande'"><br></font></span></div><p>&#160;</p><p>&#160;</p><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123581.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-16 11:31 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123581.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Object-c 细节之协议</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123502.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Sun, 15 Aug 2010 08:01:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123502.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123502.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123502.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123502.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">1.定义一个MyClass类,和一个TestShow协议:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">@protocol</span><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; </span>TestShow;<span  style="color: rgb(0, 138, 0); "><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;</span><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">		</span></span></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">@interface</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>MyClass<span style="font: 14.0px 'GB18030 Bitmap'"> </span>:<span style="font: 14.0px 'GB18030 Bitmap'"> </span>NSObject&lt;NSCopying&gt;<span  style="color: rgb(0, 138, 0); ">//</span><span  style="color: rgb(0, 138, 0); font-family: 'Lucida Grande'; font-size: 14px; "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">遵守</span></span><span  style="color: rgb(0, 138, 0); font-family: 'Lucida Grande'; font-size: 14px; ">NSCopying</span><span  style="color: rgb(0, 138, 0); font-family: 'Lucida Grande'; font-size: 14px; "><span style="font: normal normal normal 14px/normal 'GB18030 Bitmap'; ">协议</span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"> </span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; <span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #b900a3">id</span>&lt;TestShow&gt;<span style="font: 14.0px 'GB18030 Bitmap'"> </span>delegate;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@property<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">(</span>nonatomic<span style="color: #000000">,</span>retain<span style="color: #000000">)</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>id<span style="color: #000000">&lt;</span><span style="color: #548187">TestShow</span><span style="color: #000000">&gt;</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">delegate;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; color: #008a00"><span style="font: 14.0px 'Lucida Grande'">//</span>自定义代理</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="color: #b900a3">@protocol</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>TestShow</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b900a3">void</span>)show;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@end</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">2.MyClass类的实现:</p><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@implementation<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">MyClass</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@synthesize<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">delegate;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//overwrite<span style="font: 14.0px 'GB18030 Bitmap'"> </span>init<span style="font: 14.0px 'GB18030 Bitmap'"> </span>method</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b900a3">id</span>)init</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #cb2625"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #440081">NSLog</span><span style="color: #000000">(</span>@"Init<span style="font: 14.0px 'GB18030 Bitmap'"> </span>called!"<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>return<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">[</span>super<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #440081">init</span><span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span  style="font-family: 'Lucida Grande'; color: rgb(0, 138, 0); ">//<span style="font: 14.0px 'GB18030 Bitmap'"> </span>NSCopying<span style="font: 14.0px 'GB18030 Bitmap'"> </span>delegate's<span style="font: 14.0px 'GB18030 Bitmap'"> </span>implementation</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b900a3">id</span>)copyWithZone:(<span style="color: #7522aa">NSZone</span>*)zone</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*copy=[[<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #b900a3">self</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">class</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">allocWithZone</span>:zone]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">init</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #b900a3">return</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>copy;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">@end</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">3.测试:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.在测试类中遵守TestShow协议,并实现方法:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><span class="Apple-tab-span" style="white-space:pre">		</span><span  style="color: rgb(0, 0, 0); ">-(<span style="color: #b900a3">void</span>)show</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre">		</span>{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #cb2625"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #440081">NSLog</span><span style="color: #000000">(</span>@"In<span style="font: 14.0px 'GB18030 Bitmap'"> </span>MainViewController"<span style="color: #000000">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre">		</span>}</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 2.测试代码如下:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>test1=[[<span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">alloc</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">init</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>test2=[<span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">new</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #548187">MyClass</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>test3=[test1<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">copy</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>test3.<span style="color: #548187">delegate</span>=<span style="color: #b900a3">self</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[test3.<span style="color: #548187">delegate</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">show</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>NSLog<span style="color: #000000">(</span><span style="color: #cb2625">@"test1's:%d"</span><span style="color: #000000">,[test1</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>retainCount<span style="color: #000000">]);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>NSLog<span style="color: #000000">(</span><span style="color: #cb2625">@"test2's:%d"</span><span style="color: #000000">,[test2</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>retainCount<span style="color: #000000">]);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[test1<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">release</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[test2<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">release</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[test3<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">release</span>];</p></p></div>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-15 16:01 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>View问题小结</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123158.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Thu, 12 Aug 2010 03:11:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123158.html</guid><description><![CDATA[<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px"><br>&nbsp;</p>
<span style="FONT-SIZE: 13px; LINE-HEIGHT: 17px; FONT-FAMILY: verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">1.UIView总结:</span>
<p style="FONT-SIZE: 13px; LINE-HEIGHT: 17px; FONT-FAMILY: verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;重要属性:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;frame</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;layer</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;subviews</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;tag</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;superview</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;userInteractionEnabled</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;multipleTouchEnabled</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;center</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;重要方法</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;initWithFrame:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;addSubview:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;insertSubview:atIndex:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;insertSubview:aboveSubview:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;insertSubview:belowSubview:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;exchangeSubviewAtIndex:withSubviewAtIndex:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;drawRect:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;viewWithTag:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;removeFromSuperview</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">2.UIScrollView使用实践:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;重要的属性:</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;contentSize</p>
<p style="MARGIN: 0px; FONT: 13px/17px verdana, sans-serif; BORDER-COLLAPSE: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">&nbsp;&nbsp; &nbsp;maximumZo </p>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-12 11:11 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Object-C与标准C/C++混合编程(太利害啦!)</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123138.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Thu, 12 Aug 2010 01:13:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123138.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123138.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123138.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123138.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123138.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 说明:objective-C/C++开发语言了。除了Cocoa相关框架和库之外，像Boost、STL以及标准ANSI C运行时库均可使用。不过大家在使用这些库时还得注意自己程序的运行环境。															--------------------zhangyuntao 2010.8.12方式:1.引入头文件:#include &lt;vector&gt;#include &lt;a...&nbsp;&nbsp;<a href='http://www.cppblog.com/zhangyuntaoshe/articles/123138.html'>阅读全文</a><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123138.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-12 09:13 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123138.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>绘图小结</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/123066.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Wed, 11 Aug 2010 06:39:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/123066.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/123066.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/123066.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/123066.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/123066.html</trackback:ping><description><![CDATA[<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'; COLOR: #4500d8">1.</span>绘图总结<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>绘图前设置<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextSetRGBFillColor/CGContextSetFillColorWithColor<span style="FONT: 14px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="COLOR: #008a00">//</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #008a00">填充色</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextSetRGBStrokeColor/CGContextSetStrokeColorWithColor &nbsp; &nbsp; &nbsp;<span style="FONT: 14px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp;&nbsp;</span><span style="COLOR: #008a00">//</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #008a00">笔颜色</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextSetLineWidth<span style="FONT: 14px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="COLOR: #008a00">//</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #008a00">线宽度</span></p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>绘图后设置<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>注<span style="FONT: 14px 'Lucida Grande'">:</span>&nbsp; 画完图后<span style="FONT: 14px 'Lucida Grande'">,</span>必须</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>先用</span>CGContextStrokePath<span style="FONT: 14px 'GB18030 Bitmap'">来描线</span>,<span style="FONT: 14px 'GB18030 Bitmap'">即形状</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>后用</span>CGContextFillPath<span style="FONT: 14px 'GB18030 Bitmap'">来填充形状内的颜色</span>.</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'; COLOR: #4500d8">2.</span>常见图形绘制<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextFillRect/CGContextFillRects</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextFillEllipseInRect</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextAddRect/CGContextAddRects</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextAddEllipseInRect</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextAddLines</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextMoveToPoint</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextAddLineToPoint</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'; COLOR: #4500d8">3.</span>常见控制方法<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextSaveGState</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextRestoreGState</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #4500d8">4.</span><span style="FONT: 14px 'GB18030 Bitmap'">创建内存图像</span>context:</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGBitmapContextCreate<span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; &nbsp; &nbsp; </span>&lt;-----CGContextRlease<span style="FONT: 14px 'GB18030 Bitmap'">释放</span></p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGColorSpaceCreateWithName<span style="FONT: 14px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>(KCGColorSpaceGenericRGB)</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGColorSpaceRlease</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #440081">CGBitmapContextCreateImage</span>()<span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; </span>&lt;-----CGImageRlease<span style="FONT: 14px 'GB18030 Bitmap'"> 释放</span>.</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'">eg:</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #7522aa">CGContextRef</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>MyCreateBitmapContext<span style="FONT: 14px 'GB18030 Bitmap'"> </span>(<span style="COLOR: #b900a3">int</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>pixelsWide,<span style="COLOR: #b900a3">int</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>pixelsHigh)</p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">{</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #7522aa">CGContextRef</span><span style="FONT: 14px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>context<span style="FONT: 14px 'GB18030 Bitmap'"> </span>=<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #b900a3">NULL</span>;</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #7522aa"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGColorSpaceRef<span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">colorSpace;</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">void</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>*<span style="FONT: 14px 'GB18030 Bitmap'">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bitmapData;</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">int</span><span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bitmapByteCount;</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">int</span><span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>bitmapBytesPerRow;</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>bitmapBytesPerRow<span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; </span>=<span style="FONT: 14px 'GB18030 Bitmap'"> </span>(pixelsWide<span style="FONT: 14px 'GB18030 Bitmap'"> </span>*<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #4500d8">4</span>);</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>bitmapByteCount<span style="FONT: 14px 'GB18030 Bitmap'"> &nbsp; &nbsp; </span>=<span style="FONT: 14px 'GB18030 Bitmap'"> </span>(bitmapBytesPerRow<span style="FONT: 14px 'GB18030 Bitmap'"> </span>*<span style="FONT: 14px 'GB18030 Bitmap'"> </span>pixelsHigh);</p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #440081"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #000000">colorSpace</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span>CGColorSpaceCreateDeviceRGB<span style="COLOR: #000000">();</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>bitmapData<span style="FONT: 14px 'GB18030 Bitmap'"> </span>=<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #440081">malloc</span>(<span style="FONT: 14px 'GB18030 Bitmap'"> </span>bitmapByteCount<span style="FONT: 14px 'GB18030 Bitmap'"> </span>);</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">if</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>(bitmapData<span style="FONT: 14px 'GB18030 Bitmap'"> </span>==<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #b900a3">NULL</span>)</p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">{</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #cb2625"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #440081">fprintf</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">(</span><span style="COLOR: #754a2c">stderr</span><span style="COLOR: #000000">,</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span>"Memory<span style="FONT: 14px 'GB18030 Bitmap'"> </span>not<span style="FONT: 14px 'GB18030 Bitmap'"> </span>allocated!"<span style="COLOR: #000000">);</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #b900a3"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>return<span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span>NULL<span style="COLOR: #000000">;</span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">}</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>context<span style="FONT: 14px 'GB18030 Bitmap'"> </span>=<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #440081">CGBitmapContextCreate</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>(bitmapData,<span style="FONT-FAMILY: 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp; &nbsp;<span style="FONT: 14px 'Lucida Grande'">pixelsWide,</span></span><span style="FONT-FAMILY: 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp; &nbsp;<span style="FONT: 14px 'Lucida Grande'">pixelsHigh,</span></span><span style="FONT-FAMILY: 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="FONT: 14px 'Lucida Grande'; COLOR: #4500d8">8</span><span style="FONT: 14px 'Lucida Grande'">,</span></span><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp;&nbsp;&nbsp;</span>bitmapBytesPerRow,<span style="FONT-FAMILY: 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp; &nbsp;<span style="FONT: 14px 'Lucida Grande'">colorSpace,</span></span><span style="COLOR: rgb(68,0,129)"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"> </span>&nbsp;&nbsp; &nbsp;</span>kCGImageAlphaPremultipliedLast<span style="COLOR: #000000">);</span></span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">if</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>(context==<span style="FONT: 14px 'GB18030 Bitmap'"> </span><span style="COLOR: #b900a3">NULL</span>)</p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">{</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #440081">free</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>(bitmapData);</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #cb2625"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #440081">fprintf</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">(</span><span style="COLOR: #754a2c">stderr</span><span style="COLOR: #000000">,</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span>"Context<span style="FONT: 14px 'GB18030 Bitmap'"> </span>not<span style="FONT: 14px 'GB18030 Bitmap'"> </span>created!"<span style="COLOR: #000000">);</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #b900a3"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>return<span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span>NULL<span style="COLOR: #000000">;</span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">}</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'; COLOR: #440081"><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGColorSpaceRelease<span style="COLOR: #000000">(</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">colorSpace</span><span style="FONT: 14px 'GB18030 Bitmap'; COLOR: #000000"> </span><span style="COLOR: #000000">);</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="COLOR: #b900a3">return</span><span style="FONT: 14px 'GB18030 Bitmap'"> </span>context;</p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'">}</span></p>
<p style="MIN-HEIGHT: 18px; MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<p style="MARGIN: 0px; FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span><span style="FONT: 14px 'Lucida Grande'; COLOR: #4500d8">5.</span>图形的变换<span style="FONT: 14px 'Lucida Grande'">:</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextTranslateCTM</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextRotateCTM</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="FONT: 14px 'GB18030 Bitmap'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGContextScaleCTM</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>&nbsp;&nbsp; 6.常用函数:</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'">&nbsp;&nbsp;<span class=Apple-tab-span style="WHITE-SPACE: pre"> </span><span style="COLOR: rgb(68,0,129)">CGRectContainsPoint();</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="COLOR: rgb(68,0,129)"></span><span style="WHITE-SPACE: pre"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGRectContainsRect();</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="WHITE-SPACE: pre"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span><span style="WHITE-SPACE: pre">CGRectIntersectsRect();</span></p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span style="WHITE-SPACE: pre"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></span>CGRectIntersection();</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>CGPointEqualToPoint();</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>CGSizeEqualToSize();</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>&nbsp;&nbsp;7.从原图片中取小图.</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'">
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span>CGImageCreateWithImageInRect</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'">8.屏幕快照:<br></p>
<p sizset="0" sizcache="5"><code><font style="BACKGROUND-COLOR: #eeeeee" face=Consolas>#import "QuartzCore/QuartzCore.h"</font></code> <br><br><code><span class=typ><font color=#2b91af>UIGraphicsBeginImageContext</font></span><span class=pun>(</span><span class=pln>yourView</span><span class=pun>.</span><span class=pln>frame</span><span class=pun>.</span><span class=pln>size</span><span class=pun>);</span><span class=pln>&nbsp;<br></span><span class=pun>[[</span><span class=pln>yourView layer</span><span class=pun>]</span><span class=pln> renderInContext</span><span class=pun>:</span><span class=typ><font color=#2b91af>UIGraphicsGetCurrentContext</font></span><span class=pun>()];</span><span class=pln>&nbsp;<br></span><span class=typ><font color=#2b91af>UIImage</font></span><span class=pln> </span><span class=pun>*</span><span class=pln>screenshot </span><span class=pun>=</span><span class=pln> </span><span class=typ><font color=#2b91af>UIGraphicsGetImageFromCurrentImageContext</font></span><span class=pun>();</span><span class=pln>&nbsp;<br></span><span class=typ><font color=#2b91af>UIGraphicsEndImageContext</font></span><span class=pun>();</span><span class=pln>&nbsp;</span></code></p>
<span class=Apple-tab-span style="WHITE-SPACE: pre"></span>
<p>&#160;</p>
<p style="MARGIN: 0px; FONT: 14px 'Lucida Grande'"><span class=Apple-tab-span style="WHITE-SPACE: pre"></span></p>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/123066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-11 14:39 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/123066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UIImageView</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/122787.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 09 Aug 2010 07:57:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/122787.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/122787.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/122787.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/122787.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/122787.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 其实,UIImageVIew为UIImage的视图容器.3.UIImage 与UIImageView的重要属性:UIImage:重要属性:sizeimageOrientation重要方法:+imageNamed:+imageWithData:drawAtPoint:drawAtPoint:blendMode:alpha:drawInRect:drawInRect:blendMode:alpha:U...&nbsp;&nbsp;<a href='http://www.cppblog.com/zhangyuntaoshe/articles/122787.html'>阅读全文</a><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/122787.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-09 15:57 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/122787.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UIViewScroll使用 </title><link>http://www.cppblog.com/zhangyuntaoshe/articles/122772.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 09 Aug 2010 06:16:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/122772.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/122772.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/122772.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/122772.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/122772.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1.官方Scrolling例子:设置每页图片的位置,及UIScrollView的大小- (void)layoutScrollImages{	UIImageView *view = nil;	N...&nbsp;&nbsp;<a href='http://www.cppblog.com/zhangyuntaoshe/articles/122772.html'>阅读全文</a><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/122772.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-09 14:16 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/122772.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>object - c细节总结</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121931.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Mon, 02 Aug 2010 02:28:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121931.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121931.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121931.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121931.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121931.html</trackback:ping><description><![CDATA[


<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">1.</span>设置实例变量值的方法通常称为设置函数<span style="font: 14.0px 'Lucida Grande'">setter,</span>而用于检索实例变量值的方法叫做获取函数<span style="font: 14.0px 'Lucida Grande'">getter.getter</span>一般为变量名<span style="font: 14.0px 'Lucida Grande'">,</span>而<span style="font: 14.0px 'Lucida Grande'">setter</span>一般为<span style="font: 14.0px 'Lucida Grande'">set+</span>变量名<span style="font: 14.0px 'Lucida Grande'">(</span>第一个字母大写<span style="font: 14.0px 'Lucida Grande'">).</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">2.</span>合成存取器方法<span style="font: 14.0px 'Lucida Grande'">:</span> 在接口定义部分使用<span style="font: 14.0px 'Lucida Grande'; color: #b900a3">@property</span>指令标识属性<span style="font: 14.0px 'Lucida Grande'">,</span>然后在实现部分使用<span style="font: 14.0px 'Lucida Grande'; color: #b900a3">@synthesize</span>指令即可<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">&nbsp;eg:<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp;</span><span style="color: #b900a3">@property</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">int</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>sum;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><font color="#000000" face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</font>@synthesize<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">sum;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">3.</span>创建方法名时<span style="font: 14.0px 'Lucida Grande'">,</span>参数名实际上是可选的<span style="font: 14.0px 'Lucida Grande'">.</span>如</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>-(<span style="color: #b900a3">int</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>set:<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(<span style="color: #b900a3">int</span>)n<span style="font: 14.0px 'GB18030 Bitmap'"> </span>:(<span style="color: #b900a3">int</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>d;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>这个方法名为<span style="font: 14.0px 'Lucida Grande'">:</span> <span style="font: 14.0px 'Lucida Grande'">set::,</span>要调用这个方法如下<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[<span style="font: 14.0px 'GB18030 Bitmap'"> </span>aFraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>set:<span style="color: #4500d8">1</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>:<span style="color: #4500d8">3</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #4500d8">4.</span><span style="font: 14.0px 'GB18030 Bitmap'">静态变量声明仍为</span>static<span style="font: 14.0px 'GB18030 Bitmap'">关键字修饰</span>,<span style="font: 14.0px 'GB18030 Bitmap'">如</span>:<span style="color: #b900a3">static</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">int</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>hiCount=<span style="color: #4500d8">0</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">5.</span>有一个名为<span style="font: 14.0px 'Lucida Grande'">new</span>的方法可以将<span style="font: 14.0px 'Lucida Grande'">alloc</span>和<span style="font: 14.0px 'Lucida Grande'">init</span>的操作结合起来<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg:<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;</span>Fraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*myFraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[Fraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">new</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">6.</span><span style="font: 14.0px 'Lucida Grande'; color: #b900a3">id</span>类型可以存任何的对象<span style="font: 14.0px 'Lucida Grande'">,</span>而且对于返回值和参数类型来说<span style="font: 14.0px 'Lucida Grande'">,</span><span style="font: 14.0px 'Lucida Grande'; color: #b900a3">id</span>是默认的类型<span style="font: 14.0px 'Lucida Grande'">,</span>如下声名了一个返回为<span style="font: 14.0px 'Lucida Grande'">id</span>类型的方法<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-allocInit;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">7.</span>承继时方法的调用<span style="font: 14.0px 'Lucida Grande'">:</span>首先检查该对象所属的类<span style="font: 14.0px 'Lucida Grande'">,</span>如果有指定名称的方法<span style="font: 14.0px 'Lucida Grande'">,</span>则调用它<span style="font: 14.0px 'Lucida Grande'">,</span>如果没有<span style="font: 14.0px 'Lucida Grande'">,</span>就检查它的父类<span style="font: 14.0px 'Lucida Grande'">,</span>父类有时则调用<span style="font: 14.0px 'Lucida Grande'">,</span>否则继续向上寻找<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">8.</span>分类<span style="font: 14.0px 'Lucida Grande'">(category)</span>机制允许你以模块方式向现有类定义添加新方法<span style="font: 14.0px 'Lucida Grande'">,</span>也就是<span style="font: 14.0px 'Lucida Grande'">,</span>不必经常给同一接口和实现文件增加新定义<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: #b900a3">@interface</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>Fraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(MathOps)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//fun<span style="font: 14.0px 'GB18030 Bitmap'"> </span>declaration...</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; <span style="font: 14.0px 'Lucida Grande'; color: #b900a3">@end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px">&nbsp;&nbsp; &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #b900a3">@implementation</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>Fraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>(MathOps)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//fun<span style="font: 14.0px 'GB18030 Bitmap'"> </span>implement...</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; <span style="font: 14.0px 'Lucida Grande'; color: #b900a3">@end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #4500d8">9.</span><span style="color: #b900a3">@class</span><span style="font: 14.0px 'GB18030 Bitmap'"> 类名</span>,<span style="font: 14.0px 'GB18030 Bitmap'">为向前声名</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">10.</span>编译时检查和运行时检查<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>在给指定类型对象发送消息时<span style="font: 14.0px 'Lucida Grande'">,</span>为编译时检查<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>而给<span style="font: 14.0px 'Lucida Grande'">id</span>类型对象发送消息时<span style="font: 14.0px 'Lucida Grande'">,</span>为运行时检查<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span><span style="color: #4500d8">11.</span>RTTI:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;</span><span style="color: #4500d8">1.</span><span style="font: 14.0px 'GB18030 Bitmap'">获得类对象</span>:<span style="font: 14.0px 'GB18030 Bitmap'"> &nbsp; </span>[Square<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">class</span>]</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre">				</span>&nbsp;&nbsp; &nbsp;eg:</span>如查看<span style="font: 14.0px 'Lucida Grande'">obj1</span>与<span style="font: 14.0px 'Lucida Grande'">obj2</span>是不是相同的类的实例<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;</span><span style="color: #b900a3">if</span>([obj1<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">class</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>==<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[obj2<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">class</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>...</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;<span style="font: 14.0px 'Lucida Grande'; color: #4500d8">2.</span>查看变量是不是不<span style="font: 14.0px 'Lucida Grande'">Fraction</span>类的实例<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>[myFraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span>isMemberOf:<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[Fraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">class</span>]];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;<span style="font: 14.0px 'Lucida Grande'; color: #4500d8">3.</span>要查看实例是否响应指定方法<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;</span>[myFraction<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">instancesRespondToSelector</span>:<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">@selector</span>(setTo:over:)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">12.</span>如果类包含多个初始化的方法<span style="font: 14.0px 'Lucida Grande'">,</span>其中一个就应该是指定的<span style="font: 14.0px 'Lucida Grande'">(designated)</span>初始化方法<span style="font: 14.0px 'Lucida Grande'">,</span>并且其它所有初始化方法都使用这个初始化方法<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">13.</span>协议<span style="font: 14.0px 'Lucida Grande'">:</span>多个类共享的一个方法列表<span style="font: 14.0px 'Lucida Grande'">,</span>协议中列出的方法没有相应的实现<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><span style="color: #000000">eg:</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;</span>@protocol<span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #7522aa">NSCopying</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>-(<span style="color: #b900a3">id</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>copyWithZone:(<span style="color: #7522aa">NSZone</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>*)zone;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #b900a3"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>@end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>注意<span style="font: 14.0px 'Lucida Grande'">:</span>协议是无类的<span style="font: 14.0px 'Lucida Grande'">,</span>它不引用任何类<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">14.</span>预处理程序<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp; <span style="font: 14.0px 'Lucida Grande'; color: #4500d8">1.</span> &nbsp; <span style="font: 14.0px 'Lucida Grande'">#define</span> &nbsp; 与<span style="font: 14.0px 'Lucida Grande'">C</span>语言的相同<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;&nbsp;<span style="font: 14.0px 'Lucida Grande'; color: #4500d8">2.</span> 条件编译<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font: 14.0px 'GB18030 Bitmap'"> </span>#ifdef<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><font face="'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font>...</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #else</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;&nbsp;</span>... &nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #endif</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">15.</span>语言的基本特性<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;<span style="font: 14.0px 'Lucida Grande'; color: #4500d8">1.</span>数组初始化不同之处<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;可以通过将元素编号放在一对大括号中可以以任意顺序初始化指定的数组元素<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg:<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color: #b900a3">int</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>x=<span style="color: #4500d8">1233</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>&nbsp;&nbsp;</span><span style="color: #b900a3">int</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>a[]={<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #4500d8">9</span>]=x+<span style="color: #4500d8">1</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #4500d8">2</span>]=<span style="color: #4500d8">3</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #4500d8">1</span>]=<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #4500d8">0</span>]=<span style="color: #4500d8">1</span>};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">16.</span>使用<span style="font: 14.0px 'Lucida Grande'">Foundation</span>提供的数组<span style="font: 14.0px 'Lucida Grande'">,</span>集合时<span style="font: 14.0px 'Lucida Grande'">,</span>它们只能存放对象<span style="font: 14.0px 'Lucida Grande'">,</span>所以不能将基本类型数据存放其中<span style="font: 14.0px 'Lucida Grande'">.</span>要存放任意基本类型<span style="font: 14.0px 'Lucida Grande'">,</span>可以使用<span style="font: 14.0px 'Lucida Grande'">NSNumber</span>类根据这些数据类型来创建对象<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg:<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color: #7522aa">NSNumber</span><span style="font: 14.0px 'GB18030 Bitmap'">类方法</span>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>+(<span style="color: #7522aa">NSNumber</span>*)numberWithInteger:(<span style="color: #b900a3">int</span>)<span style="font: 14.0px 'GB18030 Bitmap'"> </span>value;<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>numberWithFloat;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>numberWithLong;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>numberWithChar;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>integerValue<span style="font: 14.0px 'GB18030 Bitmap'"> </span>longValue<span style="font: 14.0px 'GB18030 Bitmap'"> </span>floatValue<span style="font: 14.0px 'GB18030 Bitmap'"> </span>doubleVaue<span style="font: 14.0px 'GB18030 Bitmap'"> </span>charValue</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>一般来说<span style="font: 14.0px 'Lucida Grande'">,</span>你负责对此类的检索<span style="font: 14.0px 'Lucida Grande'">,</span>如果在<span style="font: 14.0px 'Lucida Grande'">NSNumber</span>对象中存储了一个值<span style="font: 14.0px 'Lucida Grande'">,</span>那么也要用一致的方式进行检索<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">17.</span>对于<span style="font: 14.0px 'Lucida Grande'">NSArray.</span>类方法<span style="font: 14.0px 'Lucida Grande'">arrayWithObjects:</span>可以用来创建使用一列对象作为元素的数组<span style="font: 14.0px 'Lucida Grande'">,</span>必须把该列表的最后一个值指定为<span style="font: 14.0px 'Lucida Grande'">nil,</span>它实际上并不存在数组中<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>要使用数组索引数来检索其中一个元素<span style="font: 14.0px 'Lucida Grande'">,</span>用<span style="font: 14.0px 'Lucida Grande'">objectAtIndex:</span>方法<span style="font: 14.0px 'Lucida Grande'">.</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span style="font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre">			</span>&nbsp;&nbsp; &nbsp;18.各种容器类如:NSArray,NSDictionary,NSSet等,会将引入的元素的引用计数值来加1来获得所有权,而元素被移除时或者整个窗口对象被释放时,释放容器内所有权.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span><span style="font: 14.0px 'Lucida Grande'; color: #4500d8">19.</span>快速枚举数组或集合中的对象<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">eg: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b900a3">for</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>(AddressCard<span style="font: 14.0px 'GB18030 Bitmap'"> </span>*theCard<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #b900a3">in</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span>book)<span style="font: 14.0px 'GB18030 Bitmap'">&nbsp;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"><span class="Apple-tab-span" style="white-space:pre">	</span></span>//op<span style="font: 14.0px 'GB18030 Bitmap'"> </span>theCard...</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>20<span style="font: 14.0px 'Lucida Grande'; color: #4500d8">.</span>复制对象<span style="font: 14.0px 'Lucida Grande'">:</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>Foundation<span style="font: 14.0px 'GB18030 Bitmap'">类提供了名为</span>copy<span style="font: 14.0px 'GB18030 Bitmap'">和</span>mutableCopy<span style="font: 14.0px 'GB18030 Bitmap'">方法</span>,<span style="font: 14.0px 'GB18030 Bitmap'">可以使用这些方法创建对象的副本</span>.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>注意<span style="font: 14.0px 'Lucida Grande'">:</span>产生一个对象的可变副本并不要求被复制对象本身是可变的<span style="font: 14.0px 'Lucida Grande'">.</span>这种情况同样适用于不可变副本<span style="font: 14.0px 'Lucida Grande'">,</span>可以创建可变对象的不可变副本<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; 使用<span style="font: 14.0px 'Lucida Grande'">copy</span>或<span style="font: 14.0px 'Lucida Grande'">mutableCopy</span>方法创建的对象采用的是浅复制<span style="font: 14.0px 'Lucida Grande'">,</span>它意味着使用<span style="font: 14.0px 'Lucida Grande'">mutableCopy</span>方法复制数组时<span style="font: 14.0px 'Lucida Grande'">,</span>在内存中为新的数组对象分配了空间<span style="font: 14.0px 'Lucida Grande'">.</span>并且单个元素复制到新数组中<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; 要使自己的类支持<span style="font: 14.0px 'Lucida Grande'">copy</span>方法<span style="font: 14.0px 'Lucida Grande'">,</span>则自己的类必须尊守<span style="font: 14.0px 'Lucida Grande'">&lt;</span><span style="font: 14.0px 'Lucida Grande'; color: #7522aa">NSCopying</span><span style="font: 14.0px 'Lucida Grande'">&gt;</span>协议<span style="font: 14.0px 'Lucida Grande'">.</span> 实现 <span style="font: 14.0px 'Lucida Grande'">copyWithZone:</span>方法来响应<span style="font: 14.0px 'Lucida Grande'">copy</span>消息<span style="font: 14.0px 'Lucida Grande'">.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p></div><div><span class="Apple-tab-span" style="white-space:pre"><br></span></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121931.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-08-02 10:28 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121931.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 Notifications</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121776.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Sat, 31 Jul 2010 06:25:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121776.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121776.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121776.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121776.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121776.html</trackback:ping><description><![CDATA[


<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(50, 62, 50); font-family: simsun; font-size: 14px; "><font color="#000000" face="Times"><span style="line-height: normal; font-size: medium;"><font color="#323E32" face="simsun" size="4"><span style="font-size: 14px; line-height: 21px;"></span></font></span></font></p><font color="#000000" face="Times"><font color="#323E32" face="simsun" size="4"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">//<span style="font: 14.0px 'GB18030 Bitmap'">通知为</span>MVC<span style="font: 14.0px 'GB18030 Bitmap'">中</span>Controller<span style="font: 14.0px 'GB18030 Bitmap'">的第三种方式</span>,<span style="font: 14.0px 'GB18030 Bitmap'">也是最高级的方式</span>,<span style="font: 14.0px 'GB18030 Bitmap'">其类似与</span>windows<span style="font: 14.0px 'GB18030 Bitmap'">上的</span>SendMessage<span style="font: 14.0px 'GB18030 Bitmap'">与</span>PostMessage<span style="font: 14.0px 'GB18030 Bitmap'">一样</span>.<span style="font: 14.0px 'GB18030 Bitmap'">使用如下</span>:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00">1.将要监听的对象加入Notification center:<span style="color: rgb(0, 0, 0); ">(一般在 viewDidLoad中)</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #008a00"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">[[</span><span style="color: #7522aa">NSNotificationCenter</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>defaultCenter<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>addObserver<span style="color: #000000">:</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #b900a3">self</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>selector<span style="color: #000000">:</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #b900a3">@selector</span><span style="color: #000000">(</span><span style="color: #35595d">showHere</span><span style="color: #000000">:)</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>name<span style="color: #000000">:</span><span style="color: #cb2625">@"update"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>object<span style="color: #000000">:</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #b900a3">nil</span><span style="color: #000000">];</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">//将对象自己加入通知信息中心,当收到@"update"通知时,将调用showHere:函数.</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">2.实现showHere函数:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">-(<span style="color: #b900a3">void</span>)showHere:(<span style="color: #b900a3">id</span>)sender</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><font color="#000000" face="'GB18030 Bitmap'">&nbsp;<span class="Apple-tab-span" style="white-space:pre">	</span></font><span style="color: #7522aa">UIAlertView</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #000000">*alert=[[</span><span style="color: #7522aa">UIAlertView</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>alloc<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>initWithTitle<span style="color: #000000">:</span><span style="color: #cb2625">@"HelloWorld"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>message<span style="color: #000000">:</span><span style="color: #cb2625">@"In</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #cb2625"> </span><span style="color: #cb2625">MainViewController!"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000">&nbsp; </span>delegate<span style="color: #000000">:</span><span style="color: #b900a3">self<span class="Apple-tab-span" style="white-space:pre">								</span></span>cancelButtonTitle<span style="color: #000000">:</span><span style="color: #cb2625">@"Cancel"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>otherButtonTitles<span style="color: #000000">:</span><span style="color: #b900a3">nil</span><span style="color: #000000">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span style="font-family: 'Lucida Grande'; "><span style="font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span></span>[alert<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">show</span>];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span class="Apple-tab-span" style="white-space:pre"><font face="'GB18030 Bitmap'">	</font></span>[alert<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">release</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">}</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'">3.在需要的地方发送通知:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">[[</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span><span style="color: #7522aa">NSNotificationCenter</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>defaultCenter<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>postNotificationName<span style="color: #000000">:</span><span style="color: #cb2625">@"update"</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>object<span style="color: #000000">:</span><span style="color: #b900a3">nil</span><span style="color: #000000">];</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">4.从Notification Center中移除加入的对象:(一般在 viewDidUnload中)</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><font color="#000000"></font></p><font color="#000000"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #440081"><span style="color: #000000">[[</span><span style="color: #7522aa">NSNotificationCenter</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>defaultCenter<span style="color: #000000">]</span><span style="font: 14.0px 'GB18030 Bitmap'; color: #000000"> </span>removeObserver<span style="color: #000000">:</span><span style="color: #b900a3">self</span><span style="color: #000000">];</span></p></font><p>&#160;</p><p>&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><br></p><p>&#160;</p><p>&#160;</p></font></font><p>&#160;</p><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121776.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-31 14:25 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121776.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iphone编程基础代码</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121759.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Sat, 31 Jul 2010 00:31:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121759.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121759.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121759.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121759.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121759.html</trackback:ping><description><![CDATA[


<div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Logging</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">In Xcode, click Run &gt; Console to see NSLog statements.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
NSLog(@"log: %@ ", myString);
NSLog(@"log: %f ", myFloat);
NSLog(@"log: %i ", myInt);
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Display Images</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Display an image anywhere on the screen, without using UI Builder. You can use this for other types of views as well.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"myImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Application Frame</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Use "<strong>bounds</strong>" instead of "<strong>applicationFrame</strong>" -- the latter will introduce a 20 pixel empty status bar (unless you want that..)</div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Web view</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">A basic UIWebView.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self addSubview:webView]; 
[webView release];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Display the Network Activity Status Indicator</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">This is the rotating icon displayed on the iPhone status bar in the upper left to indicate there is background network activity taking place.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Animation: Series of images</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Show a series of images in succession<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
NSArray *myImages = [NSArray arrayWithObjects:
	[UIImage imageNamed:@"myImage1.png"],
	[UIImage imageNamed:@"myImage2.png"],
	[UIImage imageNamed:@"myImage3.png"],
	[UIImage imageNamed:@"myImage4.gif"],
	nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];    
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Animation: Move an object</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Show something moving across the screen. Note: this type of animation is "fire and forget" -- you cannot obtain any information about the objects during animation (such as current position). If you need this information, you will want to animate manually using a Timer and adjusting the x&amp;y coordinates as necessary.</div></div><div><br></div><div><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; "><div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
CABasicAnimation *theAnimation;	
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=1;
theAnimation.repeatCount=2;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-60];
[view.layer addAnimation:theAnimation forKey:@"animateLayer"];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">NSString and int</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">The following example displays an integer's value as a text label:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
currentScoreLabel.text = [NSString stringWithFormat:@"%d", currentScore];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Regular Expressions (RegEx)</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">There is currently no easy way to do RegEx with the framework. You cannot use any regex involving NSPredicate on iPhone -- it may work in Simulator, but does not work on the device!</div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Draggable items</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Here's how to create a simple draggable image.<br>1. Create a new class that inherits from UIImageView<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
@interface myDraggableImage : UIImageView {
}
			</div>2. In the implementation for this new class, add the 2 methods:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
	
	// Retrieve the touch point
	CGPoint pt = [[touches anyObject] locationInView:self];
	startLocation = pt;
	[[self superview] bringSubviewToFront:self];
	
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
	
	// Move relative to the original touch point
	CGPoint pt = [[touches anyObject] locationInView:self];
	CGRect frame = [self frame];
	frame.origin.x += pt.x - startLocation.x;
	frame.origin.y += pt.y - startLocation.y;
	[self setFrame:frame];
}
			</div>3. Now instantiate the new class as you would any other new image and add it to your view<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
dragger = [[myDraggableImage alloc] initWithFrame:myDragRect];
[dragger setImage:[UIImage imageNamed:@"myImage.png"]];
[dragger setUserInteractionEnabled:YES];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Vibration and Sound</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Here is how to make the phone vibrate (Note: Vibration does not work in the Simulator, it only works on the device.)<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
			</div>Sound will work in the Simulator, however some sound (such as looped) has been reported as not working in Simulator or even altogether depending on the audio format. Note there are specific filetypes that must be used (.wav in this example).<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
SystemSoundID pmph;
id sndpath = [[NSBundle mainBundle] 
	pathForResource:@"mySound" 
	ofType:@"wav" 
	inDirectory:@"/"];
CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
AudioServicesCreateSystemSoundID (baseURL, &amp;pmph);
AudioServicesPlaySystemSound(pmph);	
[baseURL release];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Threading</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">1. Create the new thread:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
[NSThread detachNewThreadSelector:@selector(<strong>myMethod</strong>) 
		toTarget:self 
		withObject:nil];
			</div>2. Create the method that is called by the new thread:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
- (void)<strong>myMethod</strong> {
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
				    
	*** code that should be run in the new thread goes here ***
				   
	[pool release];
}
			</div>What if you need to do something to the main thread from inside your new thread (for example, show a loading symbol)? Use<strong>performSelectorOnMainThread</strong>.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
[self performSelectorOnMainThread:@selector(<strong>myMethod</strong>) 
	withObject:nil 
	waitUntilDone:false];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Reading crash logs</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">If you're in the unfortunate position of having to decipher a crash log,&nbsp;<a href="http://www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/" target="_blank">navigate here</a>&nbsp;to give them meaning.</div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Testing</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">1. In Simulator, click Hardware &gt; Simulate Memory Warning to test. You may need to enable this setting on each new page of your app.<br>2. Be sure to test your app in Airplane Mode.<br></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Access properties/methods in other classes</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">One way to do this is via the AppDelegate:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
myAppDelegate *appDelegate 
	= (myAppDelegate *)[[UIApplication sharedApplication] delegate];
[[[appDelegate rootViewController] flipsideViewController] myMethod];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Random Numbers</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Use&nbsp;<strong>arc4random()</strong>. There is also&nbsp;<strong>random()</strong>, but you must seed it manually, so arc4random() is preferred.</div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Timers</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">This timer will call&nbsp;<strong>myMethod</strong>&nbsp;every 1 second.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
[NSTimer scheduledTimerWithTimeInterval:1 
	target:self 
	selector:@selector(<strong>myMethod</strong>) 
	userInfo:nil 
	repeats:YES];
			</div>What if you need to pass an object to&nbsp;<strong>myMethod</strong>? Use the "userInfo" property.&nbsp;<br>1. First create the Timer<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
[NSTimer scheduledTimerWithTimeInterval:1 
	target:self 
	selector:@selector(<strong>myMethod</strong>) 
	userInfo:<strong>myObject</strong> 
	repeats:YES];
			</div>2. Then pass the NSTimer object to your method:<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
-(void)<strong>myMethod</strong>:<strong>(NSTimer*)timer</strong> {

	// Now I can access all the properties and methods of <strong>myObject</strong>
	[<strong>[timer userInfo]</strong> myObjectMethod];
}
			</div>To stop a timer, use "invalidate":<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
[myTimer invalidate];
myTimer = nil; // ensures we never invalidate an already invalid Timer
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Application analytics</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">When you release, you might want to collect data on how often your app is being used. Most people are using&nbsp;<a href="http://www.pinchmedia.com/" target="_blank">PinchMedia</a>&nbsp;for this. They give you Obj-C code that is easy to add to your app and then view statistics through their website.</div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Time</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Calculate the passage of time by using&nbsp;<strong>CFAbsoluteTimeGetCurrent()</strong>.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
CFAbsoluteTime myCurrentTime = CFAbsoluteTimeGetCurrent();
// perform calculations here
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Alerts</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Show a simple alert with OK button.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" 
		delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Plist files</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Application-specific plist files can be stored in the Resources folder of the app bundle. When the app first launches, it should check if there is an existing plist in the user's Documents folder, and if not it should copy the plist from the app bundle.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
// Look in Documents for an existing plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(
	NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
myPlistPath = [documentsDirectory stringByAppendingPathComponent: 
	[NSString stringWithFormat: @"%@.plist", plistName] ];
[myPlistPath retain];

// If it's not there, copy it from the bundle
NSFileManager *fileManger = [NSFileManager defaultManager];
if ( ![fileManger fileExistsAtPath:myPlistPath] ) {
	NSString *pathToSettingsInBundle = [[NSBundle mainBundle] 
		pathForResource:plistName ofType:@"plist"];
}		
			</div>Now read the plist file from Documents<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
NSArray *paths = NSSearchPathForDirectoriesInDomains(
	NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *path = [documentsDirectoryPath 
	stringByAppendingPathComponent:@"myApp.plist"];
NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];
			</div>Now read and set key/values<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
myKey = (int)[[plist valueForKey:@"myKey"] intValue];
myKey2 = (bool)[[plist valueForKey:@"myKey2"] boolValue];

[plist setValue:myKey forKey:@"myKey"];
[plist writeToFile:path atomically:YES];
	
			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Info button</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">Increase the touchable area on the Info button, so it's easier to press.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x-25, 
	infoButton.frame.origin.y-25, infoButton.frame.size.width+50, 
	infoButton.frame.size.height+50);
[infoButton setFrame:newInfoButtonRect];

			</div></div><h3 style="clear: right; color: rgb(85, 107, 47); font-size: 1.5em; border-top-style: dotted; border-top-width: 1px; border-top-color: black; margin-top: 20px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: helvetica, verdana, sans-serif; ">Detecting Subviews</h3><div class="topic" style="color: rgb(51, 0, 0); font-family: helvetica, verdana, sans-serif; font-size: 12px; ">You can loop through subviews of an existing view. This works especially well if you use the "tag" property on your views.<div class="snippet" style="background-color: rgb(247, 247, 247); margin-top: 25px; margin-right: 35px; margin-bottom: 25px; margin-left: 35px; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; border-left-color: rgb(211, 211, 211); font-family: Monaco, monospace; white-space: pre; ">
for (UIImageView *anImage in [self.view subviews]) {
	if (anImage.tag == 1) {
		// do something
	}
}
			</div><div><br></div></div></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-31 08:31 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121759.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FAQ 链接</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121756.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Fri, 30 Jul 2010 23:00:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121756.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121756.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121756.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121756.html</trackback:ping><description><![CDATA[
<a href="http://www.cocoachina.com/bbs/read.php?tid-15963.html"><u>内存管理</u></a> <br><br>http://bbs.weiphone.com/read-htm-tid-641817.html <br><br><a href="http://howtomakeiphoneapps.com/2009/12/how-to-use-uiscrollview-in-your-iphone-app/">http://howtomakeiphoneapps.com/2009/12/how-to-use-uiscrollview-in-your-iphone-app/</a><br><br><a href="http://stackoverflow.com/questions/2961770/uiimage-drawinrect-cgcontextdrawimage-not-releasing-memory">http://stackoverflow.com/questions/2961770/uiimage-drawinrect-cgcontextdrawimage-not-releasing-memory</a><br><br><a href="http://stackoverflow.com/questions/1431566/iphone-cgbitmapcontextcreateimage-leak-anyone-else-with-this-problem">http://stackoverflow.com/questions/1431566/iphone-cgbitmapcontextcreateimage-leak-anyone-else-with-this-problem</a><h5 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 25px; font-size: 12px; background-image: url(http://download.csdn.net/images/dot.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; border-bottom-style: solid; border-bottom-width: 4px; border-bottom-color: rgb(41, 151, 191); line-height: 24px; font-family: tahoma, verdana, arial, sans-serif; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><br></h5><div><a href="http://stackoverflow.com/questions/1431566/iphone-cgbitmapcontextcreateimage-leak-anyone-else-with-this-problem"></a><a href="http://download.csdn.net/source/286881">OpenGL编程指南（第四版）(PDF)+源码</a>&nbsp;&nbsp; &nbsp;&nbsp;http://d.download.csdn.net/down/286881/chenxhcc</div><div><br></div><div><br></div><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-31 07:00 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>view分割</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121755.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Fri, 30 Jul 2010 22:38:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121755.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121755.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121755.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121755.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'"><span class="Apple-tab-span" style="white-space:pre">	</span>把一个<span style="font: 14.0px 'Lucida Grande'">view</span>分割成四个独立的<span style="font: 14.0px 'Lucida Grande'">view,</span>每个子<span style="font: 14.0px 'Lucida Grande'">view</span>互不影响<span style="font: 14.0px 'Heiti SC Light'">：</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">#define<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_WIDTH<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[UIScreen<span style="font: 14.0px 'GB18030 Bitmap'"> </span>mainScreen].bounds.size.width</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #754a2c">#define<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[UIScreen<span style="font: 14.0px 'GB18030 Bitmap'"> </span>mainScreen].bounds.size.height</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #7522aa">UIView</span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view1<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[<span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">alloc</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">initWithFrame</span>:<span style="color: #440081">CGRectMake</span>(<span style="color: #4500d8">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #7522aa">UIView</span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view2<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[<span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">alloc</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">initWithFrame</span>:<span style="color: #440081">CGRectMake</span>(SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #4500d8">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #7522aa">UIView</span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view3<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[<span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">alloc</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">initWithFrame</span>:<span style="color: #440081">CGRectMake</span>(<span style="color: #4500d8">0</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span><span style="color: #7522aa">UIView</span>*<span style="font: 14.0px 'GB18030 Bitmap'"> </span>view4<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[[<span style="color: #7522aa">UIView</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">alloc</span>]<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">initWithFrame</span>:<span style="color: #440081">CGRectMake</span>(SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_WIDTH/<span style="color: #4500d8">2</span>,<span style="font: 14.0px 'GB18030 Bitmap'"> </span>SCREEN_HEIGHT/<span style="color: #4500d8">2</span>)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>view1.backgroundColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #7522aa">UIColor</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">redColor</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[<span style="color: #b900a3">self</span>.view<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addSubview</span>:view1];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>view2.backgroundColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #7522aa">UIColor</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">greenColor</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[<span style="color: #b900a3">self</span>.view<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addSubview</span>:view2];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>view3.backgroundColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #7522aa">UIColor</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">blueColor</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[<span style="color: #b900a3">self</span>.view<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addSubview</span>:view3];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'GB18030 Bitmap'; min-height: 18.0px"><span class="Apple-tab-span" style="white-space:pre">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>view4.backgroundColor<span style="font: 14.0px 'GB18030 Bitmap'"> </span>=<span style="font: 14.0px 'GB18030 Bitmap'"> </span>[<span style="color: #7522aa">UIColor</span><span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">yellowColor</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'"><span style="font: 14.0px 'GB18030 Bitmap'">&nbsp; &nbsp; </span>[<span style="color: #b900a3">self</span>.view<span style="font: 14.0px 'GB18030 Bitmap'"> </span><span style="color: #440081">addSubview</span>:view4];</p><img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-31 06:38 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>类定义练习</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/121118.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Fri, 23 Jul 2010 08:10:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/121118.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/121118.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/121118.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/121118.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/121118.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 4px; FONT-SIZE: 13px; BORDER-LEFT-COLOR: rgb(204,204,204); PADDING-BOTTOM: 4px; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BACKGROUND-COLOR: rgb(238,238,238)"><span style="COLOR: #000000">#import&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">Foundation</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">Foundation.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><br>@interface&nbsp;ClassA&nbsp;:&nbsp;NSObject<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x;<br>}<br><br><br>@property&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">用编译器的方法实现存取器</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;自定义实现存取器方法声明<br>-(void)setX:(int)num;<br>-(int)x;<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">重载dealloc函数.<br>&nbsp;要释放成员变量所占用的内存,应该重载dealloc函数,<br>&nbsp;而不是release函数,release函数通过掉用dealloc函数完成清理工作.</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br></span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)dealloc;<br><br><br></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">重载init函数.<br>&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br></span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(id)init;<br><br><br>@end<br>@implementation&nbsp;ClassA<br><br>@synthesize&nbsp;x;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">用编译器的方法实现存取器</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">&nbsp;自定义实现存取器方法定义<br>-(void)setX:(int)num<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;x=num;<br>}<br><br>-(int)x<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;x;<br>}<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(id)init<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;self</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">[super&nbsp;init];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;self;<br>}<br><br></span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)dealloc<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;NSLog(</span><span style="COLOR: #000000">@"</span><span style="COLOR: #000000">Dealloc&nbsp;called</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;[super&nbsp;dealloc];<br>}<br>@end<br><br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;argc,&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;argv[])&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;NSAutoreleasePool&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pool&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;[[NSAutoreleasePool&nbsp;alloc]&nbsp;init];<br><br>&nbsp;&nbsp;&nbsp;&nbsp;ClassA&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pa</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">[[ClassA&nbsp;alloc]&nbsp;init];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">存取器使用方法一<br>&nbsp;&nbsp;&nbsp;&nbsp;pa.x=5;<br>&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"pa.x=%i",pa.x);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;存取器使用方法二<br>&nbsp;&nbsp;&nbsp;&nbsp;[pa x:5];<br>&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"pa.x=%i",pa.x);<br>&nbsp;&nbsp;&nbsp;&nbsp;[pa&nbsp;release];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;使用id来操作对象指针pa<br>&nbsp;&nbsp;&nbsp;&nbsp;id&nbsp;value=pa;<br>&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"pa.x=%i",[value&nbsp;x]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;RTTI练习<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;([pa&nbsp;isMemberOfClass:[ClassA&nbsp;class]&nbsp;]==TRUE)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"pa&nbsp;is&nbsp;a&nbsp;instance&nbsp;of&nbsp;classA");<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;if([pa&nbsp;respondsToSelector:@selector(draw)]==TRUE)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[pa&nbsp;draw];<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"pa&nbsp;hasn't&nbsp;the&nbsp;fun&nbsp;of&nbsp;draw!");<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;异常处理练习<br>&nbsp;&nbsp;&nbsp;&nbsp;@try&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[pa&nbsp;draw];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;@catch&nbsp;(NSException&nbsp;*&nbsp;e)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"Caught&nbsp;%@%@",[e&nbsp;name],[e&nbsp;reason]);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;@finally&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"Here");<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000">&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;[pool&nbsp;drain];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}</span></div>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/121118.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-23 16:10 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/121118.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从 C/C++ 语言到 Objective-C 语言</title><link>http://www.cppblog.com/zhangyuntaoshe/articles/120615.html</link><dc:creator>张运涛</dc:creator><author>张运涛</author><pubDate>Sat, 17 Jul 2010 02:26:00 GMT</pubDate><guid>http://www.cppblog.com/zhangyuntaoshe/articles/120615.html</guid><wfw:comment>http://www.cppblog.com/zhangyuntaoshe/comments/120615.html</wfw:comment><comments>http://www.cppblog.com/zhangyuntaoshe/articles/120615.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhangyuntaoshe/comments/commentRss/120615.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhangyuntaoshe/services/trackbacks/120615.html</trackback:ping><description><![CDATA[<h1 style="TEXT-ALIGN: center">从 C/C++ 语言到 Objective-C 语言</h1>
<span style="COLOR: red">一.类的定义部分</span><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000"><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;C++&nbsp;Class</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">BaseClass.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MyClass&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;BaseClass<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">构造,析构函数.</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;MyClass();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">MyClass();<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">属性设置函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;GetValue()&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;SetValue(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;inValue);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据交验函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;IsValid(int inValue)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">得到实例</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;GetInstance();<br></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sInstance;<br>};<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Object-C&nbsp;Class</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;#import&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">BaseClass.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br>　　<br>&nbsp;&nbsp;&nbsp;&nbsp;@interface&nbsp;MyClass&nbsp;:&nbsp;BaseClass<br>　　{<br>&nbsp;&nbsp;&nbsp;&nbsp;　　</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">属性设置函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)&nbsp;getValue;<br>　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)&nbsp;setValue:&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)&nbsp;inValue;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">数据交验函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(BOOL)&nbsp;isValid;<br><br>　　</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)&nbsp;getInstance;<br><br>　　@end</span></div>
注: <br>&nbsp; 1.用#import取代了#include.#import 相当于 C/C++ 语言中的 #include+#pragma once。当头文件嵌套包含的时候，它的作用就发挥出来了。<br>&nbsp; 2.类中没有构造和析构函数<br>&nbsp; 3.成员变量/函数没有限定符，且成员变量默认为private,成员函数默认为public.<br>&nbsp; 4.没有const 与 virtual 关键字,且函数缺省就是virtual的。<br>&nbsp; 5.类继续的时候没有限定符,且继承都是公有继承。所有继承都是单继承.<br>&nbsp; 6.如果想实现多重继承，可以只用类似Java 中 implements 的方法。(Objective-C 中叫做 protocol).<br><span style="COLOR: red">二.类的实现部分</span><br>&nbsp;
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #008000">//</span><span style="COLOR: #008000">实现部分:</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;MyClass::sInstance&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">析构怀构造函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">MyClass::MyClass():mValue(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>{<br><br>}<br>MyClass::</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">MyClass()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;mValue</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">属性设置函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MyClass::GetValue()</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;mValue;<br>}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;MyClass::SetValue(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;inValue)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;assert(IsValid(inValue));<br>&nbsp;&nbsp;&nbsp;&nbsp;mValue</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">inValue;<br>}<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;MyClass::IsValid(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;inValue)</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;inValue&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;inValue&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">);<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">得到实例函数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;MyClass::GetInstance()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(sInstance</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">NULL)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sInstance</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;MyClass();<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;sInstance;<br>}<br><br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">MyClass::GetInstance();<br>&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">SetValue(</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">GetValue()</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">In&nbsp;Object-C&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">　　</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sInstance&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><br>　　@implementation&nbsp;MyClass<br><br>　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)&nbsp;getValue<br>　　{<br>　　</span><span style="COLOR: #0000ff">&nbsp;&nbsp; return</span><span style="COLOR: #000000">&nbsp;(mValue);<br>　　}<br><br>　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)&nbsp;setValue:&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)&nbsp;inValue<br>　　{<br>&nbsp; 　　NSParameterAssert([self&nbsp;isValid]);<br>&nbsp; 　　mValue&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;inValue;<br>　　}<br><br>　　</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;(BOOL)&nbsp;isValid<br>　　{<br>&nbsp; 　　</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;inValue&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;inValue&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">);<br>　　}<br><br>　　</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (MyClass</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)&nbsp;getInstance<br>　　{<br>　&nbsp;&nbsp; 　</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(sInstance&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 　　sInstance&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;[MyClass&nbsp;alloc];<br>　　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; 　　</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;(sInstance);<br>　　}<br><br>　　@end</span></div>
<p align=left>注:<br>&nbsp;&nbsp; 1.实例方法:&nbsp; 方法前面的&#8220;-&#8221;是实例方法(类似于C++中的类成员函数)。<br>&nbsp;&nbsp; 2.类方法:&nbsp; &nbsp; 前缀为&#8220;+&#8221;的是类方法(类似于C++中的静态成员函数，或者是全局函数)<br>&nbsp;&nbsp; 3.类变量:&nbsp; &nbsp; 与C/C++语言中的静态变量一样，Objective-C 中的类变量就是以 static 声明的变量。(只在当前定义文件中有效)<br>&nbsp;&nbsp; 4.如果子类也想参照父类中的类变量的时候，须定义属性参照方法(类方法)。(这与面向对象中的封装概念有所背驰，降低了凝聚度)<br><br><span style="COLOR: red">类设计小结:<br></p>
</span>
<p align=left>1. 头文件依然是.h,但实现文件从 .cpp变成了.m.<br>2. #import代替了#include，#import保证只会引用一次，相当于.h里的#ifndef #define #endif模式<br>3. 用@interface &#8230; @end来声明类，取代class ClassName{}<br>4. 用@implementation &#8230; @end来实现类<br><br>5. Data Members放在@interface ClassName : Parent{ &#8230; }中，默认权限为@protected，在ObjC里称为Instance Variables<br>6. Member Functions放在@interface ClassName: Parent{} &#8230; @end中，在ObjC里称为Instance Methods<br>7. Instance Methods的声明方式为：scope (returnType) methodName: (parameter1Type) parameter1Name;<br><br>8. scope分instance和class两种，分别用-和+表示<br><br>9. 调用method的方式是[Object&nbsp; method]，相当于Object-&gt; method()<br>10. 带参数调用method的方式是[Object method: parameter]<br><br>11. 没有Object，只有Pointer to Object<br>12. 通常的构造方式： Object * obj = [[Object alloc] init]<br>13. 析构的方式：[obj release]<br><br>14.多参数method的声明方式： scope (returnType) methodName<span style="COLOR: #00ccff">: (parameter1Type) parameter1Name label1Name</span>: (parameter2Type) parameter2Name &#8230; ;<br>15.<span style="COLOR: #00ccff"> labelName</span>不是必须的<br><br>16. 这种特别的语法源自SmallTalk<br>17. private: [list of vars]&nbsp;&nbsp;&nbsp;&nbsp; protected: [list of vars]&nbsp;&nbsp;&nbsp; public: [list of vars] 改成了@private, @protected, @public<br><br>18.<span style="COLOR: #00ccff"> Class Variable</span>用static的方法实现.<br>19. <span style="COLOR: #00ccff">+(void) initialize</span> 会在构造的时候被调用<br>20. ObjC通常<span style="COLOR: #00ccff">用@符号表示语言的衍生部分<br></span><br>22. ObjC用id来表示范型对象的指针<br>23. 支持动态类型识别,即RTTI.<br><br>24. Categories机制可用于不继承已有class的前提下加入新功能<br>25. Posing机制允许Child取代Parent<br>26. Protocol相当于pure virtual class<br><br>27. ObjC由两种<span style="COLOR: #00ccff">内存管理</span>的方法，1) retain and release，2) retain and release/autorelease<br>28. <span style="COLOR: #00ccff">Foundation相当于STL</span>，NSArray对应vector，NSDictionary对应map<br>29. ObjC<span style="COLOR: #00ccff">不支持Namespace<br></span>30. <span style="COLOR: #00ccff">不支持重载</span></p>
<div id=c_jquery_test style="DISPLAY: none"></div>
<script type=text/javascript>
if ($ != jQuery) {
$ = jQuery.noConflict();
}
</script>
<img src ="http://www.cppblog.com/zhangyuntaoshe/aggbug/120615.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhangyuntaoshe/" target="_blank">张运涛</a> 2010-07-17 10:26 <a href="http://www.cppblog.com/zhangyuntaoshe/articles/120615.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>