﻿<?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++博客-厚积薄发，滴水穿石-随笔分类-IOS</title><link>http://www.cppblog.com/cokecoffe/category/17906.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 05 Jun 2012 03:19:09 GMT</lastBuildDate><pubDate>Tue, 05 Jun 2012 03:19:09 GMT</pubDate><ttl>60</ttl><item><title>NavigationController的使用</title><link>http://www.cppblog.com/cokecoffe/archive/2012/06/03/177341.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sun, 03 Jun 2012 09:34:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/06/03/177341.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/177341.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/06/03/177341.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/177341.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/177341.html</trackback:ping><description><![CDATA[<h1>1.创建</h1>
<blockquote>
<h4><span style="font-weight: normal;">通过xib创建</span></h4>
<p>通过代码创建</p>
</blockquote>
<p>一个UINavigationcontroller包括 navigation bar,可选的navigation toolbar,RootViewController.</p>
<h1>2.导航栈</h1>
<p>有四个方法</p>
<blockquote>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Wangkeke/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/pushViewController:animated:">&#8211;&nbsp;pushViewController:animated:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Wangkeke/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popViewControllerAnimated:">&#8211;&nbsp;popViewControllerAnimated:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Wangkeke/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popToRootViewControllerAnimated:">&#8211;&nbsp;popToRootViewControllerAnimated:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Wangkeke/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popToViewController:animated:">&#8211;&nbsp;popToViewController:animated:</a></code></span></li>
</ul>
</blockquote>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
例如，想推进一个新的viewcontroller，到导航栈中,代码：
</ul>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;"><span style="padding: 0px; margin: 0px; color: #002200;">-</span> <span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">void</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>tableView<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span>UITableView <span style="padding: 0px; margin: 0px; color: #002200;">*</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>tableView
        didSelectRowAtIndexPath<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #400080;">NSIndexPath</span> <span style="padding: 0px; margin: 0px; color: #002200;">*</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>indexPath <span style="padding: 0px; margin: 0px; color: #002200;">{</span>
    <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>tableView cellForRowAtIndexPath<span style="padding: 0px; margin: 0px; color: #002200;">:</span>indexPath<span style="padding: 0px; margin: 0px; color: #002200;">]</span> setSelected<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">NO</span> animated<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">YES</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;//1.
&nbsp;
    DetailsViewController <span style="padding: 0px; margin: 0px; color: #002200;">*</span>detailsViewController <span style="padding: 0px; margin: 0px; color: #002200;">=</span> <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>DetailsViewController alloc<span style="padding: 0px; margin: 0px; color: #002200;">]</span>
        initWithNibName<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">@</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">"DetailsViewController"</span> bundle<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">nil</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
    <span style="padding: 0px; margin: 0px; color: #002200;">[</span>self.navigationController pushViewController<span style="padding: 0px; margin: 0px; color: #002200;">:</span>detailsViewController<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
    <span style="padding: 0px; margin: 0px; color: #002200;">[</span>detailsViewController release<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
<span style="padding: 0px; margin: 0px; color: #002200;">}</span></pre>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
这里有两个需要注意的地方
</ul>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
1.进入下一个页面的时候，table中的选择行要取消。
</ul>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
2.记得release要push的controller.因为导航栈是retain的。
</ul>
<h1 style="font-size: 2em;"><span style="font-family: Verdana; font-size: 18pt; ">3.配置Navigation bar</span><br /></h1>
<p>可能大家想直接访问navigationcontroller 的navigation bar。但是通常我们不这样做。而是维护每个viewcontroller的 navigation item。</p>
<p>这里不要将navigation item 与 navigation bar 混淆，navigation item不是UIView的子类。它是一个用来更新navigtion bar的存储信息的类。</p>
<p>还是上代码说明:</p>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;"><span style="padding: 0px; margin: 0px; color: #002200;">-</span> <span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">void</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>tableView<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span>UITableView <span style="padding: 0px; margin: 0px; color: #002200;">*</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>tableView
        didSelectRowAtIndexPath<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #400080;">NSIndexPath</span> <span style="padding: 0px; margin: 0px; color: #002200;">*</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>indexPath <span style="padding: 0px; margin: 0px; color: #002200;">{</span>
  <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>tableView cellForRowAtIndexPath<span style="padding: 0px; margin: 0px; color: #002200;">:</span>indexPath<span style="padding: 0px; margin: 0px; color: #002200;">]</span> setSelected<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">NO</span> animated<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">YES</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
&nbsp;
  Person <span style="padding: 0px; margin: 0px; color: #002200;">*</span>person;
&nbsp;
  <span style="padding: 0px; margin: 0px; color: #11740a; font-style: italic;">// Some code that sets person based on the particular cell that was selected</span>
&nbsp;
  DetailsViewController <span style="padding: 0px; margin: 0px; color: #002200;">*</span>detailsViewController <span style="padding: 0px; margin: 0px; color: #002200;">=</span> <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>DetailsViewController alloc<span style="padding: 0px; margin: 0px; color: #002200;">]</span>
    initWithNibName<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">@</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">"DetailsViewController"</span> bundle<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">nil</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
  detailsViewController.navigationItem.title <span style="padding: 0px; margin: 0px; color: #002200;">=</span> person.name;
  <span style="padding: 0px; margin: 0px; color: #002200;">[</span>self.navigationController pushViewController<span style="padding: 0px; margin: 0px; color: #002200;">:</span>detailsViewController<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
  <span style="padding: 0px; margin: 0px; color: #002200;">[</span>detailsViewController release<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
<span style="padding: 0px; margin: 0px; color: #002200;">}</span></pre>
<pre class="objc" style="width: auto; clear: none; overflow-x: visible; overflow-y: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace; padding: 0px; margin: 0px;">detailsViewController.navigationItem.title <span style="color: #002200; padding: 0px; margin: 0px;">=</span> person.name;这句话的意思就是把二级界面的导航标题设置成person.name</pre>
<p>要注意两点:1.我们并没有直接操作navigation bar 2.在push 新的controller之前设置标题</p>
<p>当新的detailcontroller被push后，<span style="color: #222222; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">UINavigationController</span>会自动更新navigation bar。</p>
<h1>4.返回按钮</h1>
<p>默认情况下，当你将一个新的viewcontroller推入栈的时候，返回按钮将显示前一个页面的controller的 navigation item的title。</p>
<p>如果想定制返回按钮的标题还有事件的话，可以用以下代码。</p>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;">UIBarButtonItem <span style="padding: 0px; margin: 0px; color: #002200;">*</span>backButton <span style="padding: 0px; margin: 0px; color: #002200;">=</span> <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>UIBarButtonItem alloc<span style="padding: 0px; margin: 0px; color: #002200;">]</span> initWithTitle<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">@</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">"Back"</span>
      style<span style="padding: 0px; margin: 0px; color: #002200;">:</span>UIBarButtonItemStylePlain target<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">nil</span> action<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">nil</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
self.navigationItem.backBarButtonItem <span style="padding: 0px; margin: 0px; color: #002200;">=</span> backButton;
<span style="padding: 0px; margin: 0px; color: #002200;">[</span>backButton release<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;</pre>
<p>注意，这里的self是第一级的view controller。这样的话第二级的页面将显示&#8220;Back&#8221;</p>
<h1>5.左右按钮</h1>
<p>navigation item还有两个属性leftBarButtonItem rightBarButtonItem。</p>
<p>一般leftBarButtonItem只出现在RootviewController中使用，因为其他页面一般都显示一个返回按钮。</p>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;">UIBarButtonItem <span style="padding: 0px; margin: 0px; color: #002200;">*</span>settingsButton <span style="padding: 0px; margin: 0px; color: #002200;">=</span> <span style="padding: 0px; margin: 0px; color: #002200;">[</span><span style="padding: 0px; margin: 0px; color: #002200;">[</span>UIBarButtonItem alloc<span style="padding: 0px; margin: 0px; color: #002200;">]</span> initWithTitle<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">@</span><span style="padding: 0px; margin: 0px; color: #bf1d1a;">"Settings"</span>
      style<span style="padding: 0px; margin: 0px; color: #002200;">:</span>UIBarButtonItemStylePlain target<span style="padding: 0px; margin: 0px; color: #002200;">:</span>self action<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">@selector</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span>handleSettings<span style="padding: 0px; margin: 0px; color: #002200;">)</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
self.navigationItem.rightBarButtonItem <span style="padding: 0px; margin: 0px; color: #002200;">=</span> settingsButton;
<span style="padding: 0px; margin: 0px; color: #002200;">[</span>settingsButton release<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;</pre>
<p>这会在右侧添加一个&#8220;Setting&#8221;的按钮，并触发handleSetting事件。</p>
<h1>6.在首页隐藏Navigation Bar</h1>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;">在RootViewController.m中实现如下：</pre>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;"><br /></pre>
<pre class="objc" style="padding: 0px; margin: 0px; width: auto; clear: none; overflow: visible; font-size: 12px; line-height: 1.333; white-space: pre; color: #110000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; background-color: #f9f9f9; font-family: monospace;"><span style="padding: 0px; margin: 0px; color: #002200;">-</span> <span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">void</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>viewWillAppear<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">BOOL</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>animated <span style="padding: 0px; margin: 0px; color: #002200;">{</span>
	<span style="padding: 0px; margin: 0px; color: #002200;">[</span>super viewWillAppear<span style="padding: 0px; margin: 0px; color: #002200;">:</span>animated<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
&nbsp;
	<span style="padding: 0px; margin: 0px; color: #002200;">[</span>self.navigationController setNavigationBarHidden<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">YES</span> animated<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">YES</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
<span style="padding: 0px; margin: 0px; color: #002200;">}</span>
&nbsp;
<span style="padding: 0px; margin: 0px; color: #002200;">-</span> <span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">void</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>viewWillDisappear<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #002200;">(</span><span style="padding: 0px; margin: 0px; color: #a61390;">BOOL</span><span style="padding: 0px; margin: 0px; color: #002200;">)</span>animated <span style="padding: 0px; margin: 0px; color: #002200;">{</span>
	<span style="padding: 0px; margin: 0px; color: #002200;">[</span>super viewWillDisappear<span style="padding: 0px; margin: 0px; color: #002200;">:</span>animated<span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
&nbsp;
	<span style="padding: 0px; margin: 0px; color: #002200;">[</span>self.navigationController setNavigationBarHidden<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">NO</span> animated<span style="padding: 0px; margin: 0px; color: #002200;">:</span><span style="padding: 0px; margin: 0px; color: #a61390;">YES</span><span style="padding: 0px; margin: 0px; color: #002200;">]</span>;
<span style="padding: 0px; margin: 0px; color: #002200;">}</span></pre>
<p>这篇文章翻译自<a href="http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/">http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/177341.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-06-03 17:34 <a href="http://www.cppblog.com/cokecoffe/archive/2012/06/03/177341.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS5 JSON</title><link>http://www.cppblog.com/cokecoffe/archive/2012/06/02/177261.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 02 Jun 2012 15:46:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/06/02/177261.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/177261.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/06/02/177261.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/177261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/177261.html</trackback:ping><description><![CDATA[<p><span style="font-family: Tahoma;">IOS5.0开始支持JSON，所以不用第三方的解析了。</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;">//<span style="font: 11.0px 'Heiti SC Light';">将</span>Foundation(NSDictionary<span style="font: 11.0px 'Heiti SC Light';">、</span>NSData) <span style="font: 11.0px 'Heiti SC Light';">转换为</span>JSon<span style="font: 11.0px 'Heiti SC Light';">格式的</span>NSData <span style="font: 11.0px 'Heiti SC Light';">用来发送</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;">//+ dataWithJSONObject:options:error:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;">&nbsp;</p>
<p style="font: normal normal normal 11px/normal Menlo; color: #008d14; margin: 0px;">//<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">将</span>JSON<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">格式的</span>Data<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">转换为</span>Foundation(NSDictionary<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">、</span>NSData) &nbsp;&nbsp;<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">用来解析</span></p>
<p style="font: normal normal normal 11px/normal Menlo; color: #008d14; margin: 0px;">//+ JSONObjectWithData:options:error:<br /><br />code:<br /><div>https://github.com/cokecoffe/ios-demo/tree/master/HTTP</div><br /></p>
<ol class="dp-j" style="font-size: 12px; line-height: 1.4em; margin: 0px 0px 1px; padding: 2px 0px; border: 1px solid #d1d7dc; list-style: decimal; background-color: #ffffff; color: #2b91af; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span style="color: black;">解析json成dic对象 </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">-(<span class="keyword" style="color: #7f0055; font-weight: bold;">void</span><span style="color: black;">)fetchedData:(NSData*)responseData&nbsp;{</span><span class="comment" style="color: #008200;">//parse&nbsp;out&nbsp;the&nbsp;json&nbsp;dataNSError*&nbsp;error;</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> NSDictionary*&nbsp;json&nbsp;=[NSJSONSerialization </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> JSONObjectWithData:responseData&nbsp;<span class="comment" style="color: #008200;">//1</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> options:kNilOptions </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> error:&amp;error]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> NSArray*&nbsp;latestLoans&nbsp;=[json&nbsp;objectForKey:@<span class="string" style="color: blue;">"loans"</span><span style="color: black;">]; </span><span class="comment" style="color: #008200;">//2</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> NSLog(@<span class="string" style="color: blue;">"loans:&nbsp;%@"</span><span style="color: black;">,&nbsp;latestLoans); </span><span class="comment" style="color: #008200;">//3</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">} </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">把对象生成json&nbsp;string </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="comment" style="color: #008200;">//build&nbsp;an&nbsp;info&nbsp;object&nbsp;and&nbsp;convert&nbsp;to&nbsp;json</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">NSDictionary*&nbsp;info&nbsp;=[NSDictionary&nbsp;dictionaryWithObjectsAndKeys:[loan&nbsp;objectForKey:@<span class="string" style="color: blue;">"name"</span><span style="color: black;">], </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> @<span class="string" style="color: blue;">"who"</span><span style="color: black;">, </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> [(NSDictionary*)[loan&nbsp;objectForKey:@<span class="string" style="color: blue;">"location"</span><span style="color: black;">] </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> objectForKey:@<span class="string" style="color: blue;">"country"</span><span style="color: black;">], </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> @<span class="string" style="color: blue;">"where"</span><span style="color: black;">, </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> [NSNumber&nbsp;numberWithFloat:&nbsp;outstandingAmount], </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> @<span class="string" style="color: blue;">"what"</span><span style="color: black;">, </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> nil]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="comment" style="color: #008200;">//convert&nbsp;object&nbsp;to&nbsp;data</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">NSData*&nbsp;jsonData&nbsp;=[NSJSONSerialization&nbsp;dataWithJSONObject:info </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> options:NSJSONWritingPrettyPrinted&nbsp;error:&amp;error]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="comment" style="color: #008200;">//print&nbsp;out&nbsp;the&nbsp;data&nbsp;contents</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">jsonSummary.text&nbsp;=[[NSString&nbsp;alloc]&nbsp;initWithData:jsonData </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> encoding:NSUTF8StringEncoding]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">添加json方法至dic </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="annotation" style="color: #646464;">@interfaceNSDictionary</span><span style="color: black;">(JSONCategories) </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">-(NSData*)toJSON; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="annotation" style="color: #646464;">@end</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="annotation" style="color: #646464;">@implementationNSDictionary</span><span style="color: black;">(JSONCategories) </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress{ </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> NSData*&nbsp;data&nbsp;=[NSData&nbsp;dataWithContentsOfURL:[NSURL&nbsp;URLWithString:&nbsp;urlAddress]]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> __autoreleasing&nbsp;NSError*&nbsp;error&nbsp;=nil; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> id&nbsp;result&nbsp;=[NSJSONSerialization&nbsp;JSONObjectWithData:data </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> options:kNilOptions&nbsp;error:&amp;error]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> <span class="keyword" style="color: #7f0055; font-weight: bold;">if</span><span style="color: black;">(error&nbsp;!=nil)returnnil; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> <span class="keyword" style="color: #7f0055; font-weight: bold;">return</span><span style="color: black;"> result; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">} </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">-(NSData*)toJSON{ </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> NSError*&nbsp;error&nbsp;=nil; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> id&nbsp;result&nbsp;=[NSJSONSerialization&nbsp;dataWithJSONObject:self </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> options:kNilOptions&nbsp;error:&amp;error]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> <span class="keyword" style="color: #7f0055; font-weight: bold;">if</span><span style="color: black;">(error&nbsp;!=nil)returnnil; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> <span class="keyword" style="color: #7f0055; font-weight: bold;">return</span><span style="color: black;"> result; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">}<span class="annotation" style="color: #646464;">@end</span><span style="color: black;"> </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">使用列子 </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">NSDictionary*&nbsp;myInfo&nbsp;=[NSDictionary&nbsp;dictionaryWithContentsOfJSONURLString:@<span class="string" style="color: blue;">"http://www.yahoo.com/news.json"</span><span style="color: black;">]; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">NSDictionary*&nbsp;information&nbsp;=[NSDictionary&nbsp;dictionaryWithObjectsAndKeys:@<span class="string" style="color: blue;">"orange"</span><span style="color: black;">,@</span><span class="string" style="color: blue;">"apple"</span><span style="color: black;">,@</span><span class="string" style="color: blue;">"banana"</span><span style="color: black;">,@</span><span class="string" style="color: blue;">"fig"</span><span style="color: black;">,nil]; </span></span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">NSData*&nbsp;json&nbsp;=[information&nbsp;toJSON]; </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">判断是否可json化 </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"> </span></li>
<li style="font-size: 1em; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">BOOL&nbsp;isTurnableToJSON&nbsp;=[NSJSONSerialization&nbsp;isValidJSONObject:&nbsp;object] </span></li>
</ol><img src ="http://www.cppblog.com/cokecoffe/aggbug/177261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-06-02 23:46 <a href="http://www.cppblog.com/cokecoffe/archive/2012/06/02/177261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS下SQLite的简单使用</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176978.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Thu, 31 May 2012 15:37:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176978.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/176978.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176978.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/176978.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/176978.html</trackback:ping><description><![CDATA[<p>看着国外网站的教程，写了一个小例子，一个联系人的程序，包括 （姓名、地址、电话）三项内容，通过两个按钮，可以将信息保存或者查询数据库已有的信息。</p>
<p>UI就不说了，比较简单。贴一下关键代码，具体的话还是去看源代码(正想办法传，我这git出点问题)。</p>
<p> </p>
<p><strong>/*<span style="font: normal normal normal 11px/normal 'Heiti SC Light';">根据路径创建数据库并创建一个表</span>contact(id nametext addresstext phonetext)*/</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #103ffb;">void</span>)viewDidLoad</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> [</span><span style="color: #103ffb;">super</span><span style="color: #000000;"> </span>viewDidLoad<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;"><span style="color: #000000;"><span style="white-space: pre;"> </span></span>// Do any additional setup after loading the view, typically from a nib.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;"> NSString</span> *docsDir;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;"> NSArray</span> *dirPaths;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;"><span style="color: #000000;"> </span>// Get the documents directory</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> dirPaths = </span>NSSearchPathForDirectoriesInDomains<span style="color: #000000;">(</span>NSDocumentDirectory<span style="color: #000000;">, </span>NSUserDomainMask<span style="color: #000000;">, </span><span style="color: #103ffb;">YES</span><span style="color: #000000;">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">docsDir = [dirPaths <span style="color: #3995ad;">objectAtIndex</span>:0];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008d14;"><span style="color: #000000;"> </span>// Build the path to the database file</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span> databasePath<span style="color: #000000;"> = [[</span>NSString<span style="color: #000000;"> </span>alloc<span style="color: #000000;">] </span>initWithString<span style="color: #000000;">: [docsDir </span>stringByAppendingPathComponent<span style="color: #000000;">: </span><span style="color: #b22822;">@"contacts.db"</span><span style="color: #000000;">]];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span> NSFileManager<span style="color: #000000;"> *filemgr = [</span>NSFileManager<span style="color: #000000;"> </span>defaultManager<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span><span style="color: #103ffb;"> if</span><span style="color: #000000;"> ([filemgr </span>fileExistsAtPath<span style="color: #000000;">:</span>databasePath<span style="color: #000000;">] == </span><span style="color: #103ffb;">NO</span><span style="color: #000000;">) </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;"> const</span> <span style="color: #103ffb;">char</span> *dbpath = [<span style="color: #3995ad;">databasePath</span> <span style="color: #3995ad;">UTF8String</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;"> if</span> (<span style="color: #3995ad;">sqlite3_open</span>(dbpath, &amp;<span style="color: #3995ad;">contactDB</span>)==<span style="color: #103ffb;">SQLITE_OK</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;"> char</span> *errMsg;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b22822;"><span style="color: #000000;"> </span><span style="color: #103ffb;"> const</span><span style="color: #000000;"> </span><span style="color: #103ffb;">char</span><span style="color: #000000;"> *sql_stmt = </span>"CREATE TABLE IF NOT EXISTS CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT,PHONE TEXT)"<span style="color: #000000;">;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;"> if</span> (<span style="color: #3995ad;">sqlite3_exec</span>(<span style="color: #3995ad;">contactDB</span>, sql_stmt, <span style="color: #103ffb;">NULL</span>, <span style="color: #103ffb;">NULL</span>, &amp;errMsg)!=<span style="color: #103ffb;">SQLITE_OK</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;"> status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">创建表失败</span><span style="color: #b22822;">\n"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;"> else</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;"> status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">创建</span><span style="color: #b22822;">/</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">打开数据库失败</span><span style="color: #b22822;">"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><strong>/*将数据保存只数据库，当按下保存按钮的时候*/</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #103ffb;">IBAction</span>)SaveToDataBase:(<span style="color: #103ffb;">id</span>)sender</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">sqlite3_stmt</span> *statement;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span><span style="color: #103ffb;">const</span><span style="color: #000000;"> </span><span style="color: #103ffb;">char</span><span style="color: #000000;"> *dbpath = [</span>databasePath<span style="color: #000000;"> </span>UTF8String<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">if</span> (<span style="color: #3995ad;">sqlite3_open</span>(dbpath, &amp;<span style="color: #3995ad;">contactDB</span>)==<span style="color: #103ffb;">SQLITE_OK</span>) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b22822;"><span style="color: #000000;"> </span><span style="color: #3995ad;">NSString</span><span style="color: #000000;"> *insertSQL = [</span><span style="color: #3995ad;">NSString</span><span style="color: #000000;"> </span><span style="color: #3995ad;">stringWithFormat</span><span style="color: #000000;">:</span>@"INSERT INTO CONTACTS (name,address,phone) VALUES(\"%@\",\"%@\",\"%@\")"<span style="color: #000000;">,</span><span style="color: #3995ad;">name</span><span style="color: #000000;">.</span><span style="color: #3995ad;">text</span><span style="color: #000000;">,</span><span style="color: #3995ad;">address</span><span style="color: #000000;">.</span><span style="color: #3995ad;">text</span><span style="color: #000000;">,</span><span style="color: #3995ad;">phone</span><span style="color: #000000;">.</span><span style="color: #3995ad;">text</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">const</span> <span style="color: #103ffb;">char</span> *insert_stmt = [insertSQL <span style="color: #3995ad;">UTF8String</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">sqlite3_prepare_v2</span>(<span style="color: #3995ad;">contactDB</span>, insert_stmt, -1, &amp;statement, <span style="color: #103ffb;">NULL</span>);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">if</span> (<span style="color: #3995ad;">sqlite3_step</span>(statement)==<span style="color: #103ffb;">SQLITE_DONE</span>) {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">已存储到数据库</span><span style="color: #b22822;">"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">name</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@""</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">address</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@""</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">phone</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@""</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">else</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">保存失败</span><span style="color: #b22822;">"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">sqlite3_finalize</span>(statement);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span>sqlite3_close<span style="color: #000000;">(</span>contactDB<span style="color: #000000;">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><strong>/*根据输入的姓名来查询数据*/</strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">- (<span style="color: #103ffb;">IBAction</span>)SearchFromDataBase:(<span style="color: #103ffb;">id</span>)sender</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span><span style="color: #103ffb;">const</span><span style="color: #000000;"> </span><span style="color: #103ffb;">char</span><span style="color: #000000;"> *dbpath = [</span>databasePath<span style="color: #000000;"> </span>UTF8String<span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">sqlite3_stmt</span> *statement;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">if</span> (<span style="color: #3995ad;">sqlite3_open</span>(dbpath, &amp;<span style="color: #3995ad;">contactDB</span>) == <span style="color: #103ffb;">SQLITE_OK</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b22822;"><span style="color: #000000;"> </span><span style="color: #3995ad;">NSString</span><span style="color: #000000;"> *querySQL = [</span><span style="color: #3995ad;">NSString</span><span style="color: #000000;"> </span><span style="color: #3995ad;">stringWithFormat</span><span style="color: #000000;">:</span>@"SELECT address,phone from contacts where name=\"%@\""<span style="color: #000000;">,</span><span style="color: #3995ad;">name</span><span style="color: #000000;">.</span><span style="color: #3995ad;">text</span><span style="color: #000000;">];</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">const</span> <span style="color: #103ffb;">char</span> *query_stmt = [querySQL <span style="color: #3995ad;">UTF8String</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">if</span> (<span style="color: #3995ad;">sqlite3_prepare_v2</span>(<span style="color: #3995ad;">contactDB</span>, query_stmt, -1, &amp;statement, <span style="color: #103ffb;">NULL</span>) == <span style="color: #103ffb;">SQLITE_OK</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">if</span> (<span style="color: #3995ad;">sqlite3_step</span>(statement) == <span style="color: #103ffb;">SQLITE_ROW</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">NSString</span> *addressField = [[<span style="color: #3995ad;">NSString</span> <span style="color: #3995ad;">alloc</span>] <span style="color: #3995ad;">initWithUTF8String</span>:(<span style="color: #103ffb;">const</span> <span style="color: #103ffb;">char</span> *)<span style="color: #3995ad;">sqlite3_column_text</span>(statement, 0)];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">address</span>.<span style="color: #3995ad;">text</span> = addressField;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">NSString</span> *phoneField = [[<span style="color: #3995ad;">NSString</span> <span style="color: #3995ad;">alloc</span>] <span style="color: #3995ad;">initWithUTF8String</span>:(<span style="color: #103ffb;">const</span> <span style="color: #103ffb;">char</span> *)<span style="color: #3995ad;">sqlite3_column_text</span>(statement, 1    )];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">phone</span>.<span style="color: #3995ad;">text</span> = phoneField;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">已查到结果</span><span style="color: #b22822;">"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">[addressField <span style="color: #3995ad;">release</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">[phoneField <span style="color: #3995ad;">release</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #103ffb;">else</span> {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">status</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@"</span><span style="font: 11.0px 'Heiti SC Light'; color: #b22822;">未查到结果</span><span style="color: #b22822;">"</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">address</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@""</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">phone</span>.<span style="color: #3995ad;">text</span> = <span style="color: #b22822;">@""</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;"><span style="color: #3995ad;">sqlite3_finalize</span>(statement);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px;"> </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3995ad;"><span style="color: #000000;"> </span>sqlite3_close<span style="color: #000000;">(</span>contactDB<span style="color: #000000;">);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;">}</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/176978.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-31 23:37 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/31/176978.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS block 教程</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176920.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Thu, 31 May 2012 05:47:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176920.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/176920.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/31/176920.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/176920.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/176920.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://pernghh.pixnet.net/blog/trackback/eac87d412e/33563409 本文来自台湾的某开发人员的博客，被墙，感觉讲的比较易懂，所以引过来。文字简体化了，原来是繁体，变数=变量，这个注意一下。 &nbsp; 本章学习目标： 1. 了解何谓block。 2. 了解block的使用方法。 Block 是iOS在4.0之后新增的程式语法，严格来说bloc...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/05/31/176920.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/176920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-31 13:47 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/31/176920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>多继承</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/23/175943.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 23 May 2012 14:51:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/23/175943.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/175943.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/23/175943.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/175943.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/175943.html</trackback:ping><description><![CDATA[<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;">Objective-C不支持多重继承，但是我们有方法实现伪继承.</span></p>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;">举个例子，加入对象A无法处理消息fun，而对象B可以处理，此时A已经继承于类C，所以此时A不能再继承B。我们可以用消息转发的方式，来将消息转发给能够处理fun消息的对象B。</span></p>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;">当然可以这么实现</span></p>
<table style="width: 763px; background-color: #f1f5f9; border-collapse: collapse; border: 1px solid #c9d1d7; padding-bottom: 4px; color: #000000; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" cellspacing="0" cellpadding="6" width="100%" bgcolor="#F1F5F9">
<tbody>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;"><p><span style="font-family: Monaco; font-size: 12px;">1 A: </span></p><p><span style="font-family: Monaco; font-size: 12px;">2 -fun </span></p><p><span style="font-family: Monaco; font-size: 12px;">3 { </span></p><p><span style="font-family: Monaco; font-size: 12px;">4         if([B respondTo:@selector(fun)]) </span></p><p><span style="font-family: Monaco; font-size: 12px;">5         { </span></p><p><span style="font-family: Monaco; font-size: 12px;">6                 return [B fun]; </span></p><p><span style="font-family: Monaco; font-size: 12px;">7         } </span></p><p><span style="font-family: Monaco; font-size: 12px;">8         return self; </span></p><p><span style="font-family: Monaco; font-size: 12px;">9 } </span></p></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;">这样简单的将消息转发出去，但是此方式欠妥，特别是当很多消息都要A来处理，但是A又无法处理的时候，你需要实现各种fun来提供每一种方法处理方式。并且当写下代码的时候，所能处理的消息集合也就必须确定下来，也就是说是静态的。</span></p>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;">有一种解决方案可以解决此问题<em> : </em><span style="color: #666666; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none; font-family: 'Hiragino Sans GB'; font-size: 13px;"><strong>forwardInvocation</strong>：方法，此方法继承与NSObject。不过NSObject中此方法的实现，只是简单的调用了<span style="color: #666666; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">doesNotRecognizeSelector:</span></span></span></p>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;"><span style="color: #666666; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none; font-family: 'Hiragino Sans GB'; font-size: 13px;"><span style="color: #666666; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">我们要做的是重写需要转发消息的类A的<span style="color: #666666; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; font-family: 'Hiragino Sans GB'; font-size: 13px;">forwardInvocation方法，以实现将消息转发给能处理fun消息的对象。</span></span></span></span></p>
<table style="width: 763px; background-color: #f1f5f9; border-collapse: collapse; border: 1px solid #c9d1d7; padding-bottom: 4px; color: #000000; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" cellspacing="0" cellpadding="6" width="100%" bgcolor="#F1F5F9">
<tbody>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">- (void)forwardInvocation:(NSInvocation *)anInvocation</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">{</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">    if ([B respondsToSelector:[anInvocation selector])</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">        [anInvocation B];</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">    else</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">        [super forwardInvocation:anInvocation];</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin: -0.083em 0.333em 0px 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;">}</pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family: 'Hiragino Sans GB'; font-size: 13px;"><span style="color: #666666; font-family: Courier, Consolas, monospace;">还有关键一步，是重写<span style="color: #000000; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 26px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">methodSignatureForSelector方法，此方法是在向对象发送不能处理的消息的时候调用的，此方法可判断消息fun是否有效注册。如果注册过fun，那么则返回fun消息的地址之类的信息，如果无效则返回nil，那么就crash掉。所以我们要把fun消息注册为一个有效的。</span></span></span></p>
<table style="cursor: default; width: 763px; background-color: #f1f5f9; border-collapse: collapse; padding-bottom: 4px; color: #000000; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border: 1px solid #c9d1d7;" cellspacing="0" cellpadding="6" width="100%" bgcolor="#F1F5F9">
<tbody>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="cursor: text; padding: 0.5em; margin: 8px; border: 1px dashed #bbbbbb;" scope="row">
<pre style="margin-top: -0.083em; margin-right: 0.333em; margin-bottom: 0px; margin-left: 0.5em; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; line-height: 13px; white-space: pre-wrap;"><span style="color: #666666;"><span style="line-height: 13px;">   </span></span><pre style="white-space: pre-wrap; word-wrap: break-word; font-size: 12px; font-family: 'Courier New'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; padding: 0px; margin: 0px;"><span style="color: #008080;"><span style="line-height: 18px;"><pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; font-family: 'Courier New'; color: #393939; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;"><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">1</span> - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">2</span> {<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">3</span>     NSMethodSignature* signature = [super methodSignatureForSelector:selector];<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">4</span>     <br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">5</span>     <span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #0000ff;">if</span> (!signature)//如果父类中无注册fun消息，那么将B注册<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">6</span>         signature = [B methodSignatureForSelector:selector];<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">7</span>     <br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">8</span>     <span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #0000ff;">return</span> signature;<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; font-size: 12px; line-height: 1.5; color: #008080;">9</span> }</pre>
<br /></span></span></pre>
</pre>
</td>
</tr>
</tbody>
</table>
<p>这样一来，消息fun将被转发至B。</p>
<p>我们来说一下向一个对象发送消息后，系统的处理流程</p>
<p>1.首先发送消息[A fun];</p>
<p>2.系统会检查A能否响应这个fun消息，如果能响应则A响应</p>
<p>3.如果不能响应，则调用methodSignatureForSelector:来询问这个消息是否有效，包括去父类中询问。</p>
<p>4.接着调用forwardInvocation:此时步骤三返回nil或者可以处理消息的消息地址。如果nil则crash，如果有可以处理fun消息的地址，那么转发成功。</p>
<p> </p>
<p> </p><img src ="http://www.cppblog.com/cokecoffe/aggbug/175943.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-23 22:51 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/23/175943.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>界面构建</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173756.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 05 May 2012 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173756.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/173756.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/173756.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/173756.html</trackback:ping><description><![CDATA[<p>三种方法</p>
<p>1.Interface Buider</p>
<p>2.用代码实现在loadview中</p>
<p>3.loadview中加载xib文件，将对象解析</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/173756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-05 17:30 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/05/173756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Objective-C 协议 简介 +委托的实现</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173717.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 05 May 2012 02:57:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173717.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/173717.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173717.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/173717.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/173717.html</trackback:ping><description><![CDATA[<p><span style="text-decoration: underline;">简单的介绍</span></p>
<p><strong>1.1定义协议: </strong></p>
<p>创建一个.h文件</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 650px; overflow: auto; border: #cecece 1px solid; padding: 5px;"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  1: _MyProtocolName.h</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  2: @protocol MyProtocolName &lt;NSObject&gt;
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  3: @end </pre></pre>
<p>注:协议中没有变量;</p>
<p>&lt;NSObject&gt;是代表在此声明的协议是NSObject协议的衍生协议（不是NSObject类);</p>
<p><strong>1.2使用协议: </strong></p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 650px; overflow: auto; border: #cecece 1px solid; padding: 5px;"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  1: @interface CustomView:UIView&lt;MyProtocolName&gt; </pre>
</pre>
<p>代表CustomView遵循我们制定的这个协议，需要实现协议的方法</p>
<p><strong>1.3用协议修饰变量: </strong></p>
<p>如果这样定义一个变量:</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 657px; height: 31px; overflow: auto; border: #cecece 1px solid; padding: 5px;"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  1:   id&lt;MyProtocolName&gt;myNewVariable;</pre>
</pre>
<p>那么myNewVaiable是遵循我们制定的这个MyProtocolName协议的</p>
<p>&nbsp;</p>
<p>如果定义函数时:</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 657px; height: 33px; overflow: auto; border: #cecece 1px solid; padding: 5px;"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">  1: - (<span style="color: #0000ff;">void</span>) doSomethingWithThisObject: (id&lt;MyProtocolName&gt;) aObject</pre>
</pre>
<p>那么这个函数的参数是需要遵循我们制定的这个MyProtocolName协议的</p>
<p>&nbsp;</p>
<p>============接下来看下如何利用协议实现委托=========</p>
<p>目的：将A的事情委托给B来做<br />&nbsp;步骤1.在A中声明协议，即要委托出去的事情（方法）。<br />&nbsp;步骤2.A中声明一个委托对象，即要委托给谁去办，用id&lt;协议名字&gt;委托对象名；<br />&nbsp;步骤3.比如想让B做A的事情，那么B的interface中要宣布自己遵循A中制定的那个协议。<br />&nbsp;步骤4.A调用委托执行那件事情去.即[delegate fun]<br /><br /></p>
<p><span style="text-decoration: underline;"><strong>A.h------------------------------------------------</strong></span></p>
<p>@protocol Mydelegate//协议的声明</p>
<p>-(void)Fun;</p>
<p>@end</p>
<p>&nbsp;</p>
<p>@interface A:NSObject</p>
<p>{</p>
<p>&nbsp; &nbsp;id&lt;Mydelegate&gt; delegate;//声明一个委托对象，我们要把事情委托给实现Mydelegate协议的类</p>
<p>}</p>
<p>@property(assign,nonatomic) id&lt;Mydelegate&gt; delegate;</p>
<p>@end</p>
<p><span style="text-decoration: underline;"><strong>A.m---------------------------------------------</strong></span></p>
<p>@implementation</p>
<p>-(void)init</p>
<p>{</p>
<p>&nbsp; &nbsp; delegate = B;</p>
<p>}</p>
<p>-(void)FunToOther</p>
<p>{</p>
<p>&nbsp; &nbsp; [delegate Fun];//将消息发送给委托去处理</p>
<p>}</p>
<p>@end</p>
<p>&nbsp;</p>
<p>委托对象的实现</p>
<p><strong>B.h---------------------------------------------</strong></p>
<p>#import"A.h"</p>
<p>@interface B:NSObject&lt;MyDelegate&gt;</p>
<p>@end</p>
<p><strong>B.m</strong><strong>---------------------------------------------</strong></p>
<p>@implementation</p>
<p>-(void)fun</p>
<p>{</p>
<p>&nbsp; &nbsp; //实现Mydelegate中制定的方法</p>
<p>}</p>
<p>@end</p>
<p>这样的话A就可以委托B去做fun这件事情了。</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/173717.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-05-05 10:57 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/05/173717.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Objective-C中委托和协议</title><link>http://www.cppblog.com/cokecoffe/archive/2012/04/25/172777.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 25 Apr 2012 15:18:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/04/25/172777.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/172777.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/04/25/172777.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/172777.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/172777.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:http://mobile.51cto.com/iphone-283416.htmObjective-C中委托和协议是本文要介绍的内容，委托和协议是两个概念，协议实际上相当于C++中的纯虚类的概念，只定义并只能由其它类来实现。而委托类似于Java中的接口。（Objective-C实现委托这种机制是利用协议来实现的，这种说法我现在认为是不对的，理由下述：）。Objective-C委...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/04/25/172777.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/172777.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-04-25 23:18 <a href="http://www.cppblog.com/cokecoffe/archive/2012/04/25/172777.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Foundation Kit</title><link>http://www.cppblog.com/cokecoffe/archive/2012/04/22/172345.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sun, 22 Apr 2012 08:58:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/04/22/172345.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/172345.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/04/22/172345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/172345.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/172345.html</trackback:ping><description><![CDATA[<p>1.<strong>NSRange</strong>  <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>typedef <span class="kwrd">struct</span> _NSRange</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span>{</pre><pre><span class="lnum">   4:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   5:  </span>    unsigned <span class="kwrd">int</span> location;</pre><pre><span class="lnum">   6:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   7:  </span>    usingned <span class="kwrd">int</span> length;</pre><pre><span class="lnum">   8:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   9:  </span>}NSRange;</pre><pre><span class="lnum"> </span>&nbsp;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>三种创建NSRange的方法： 
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>  1.NSRange range;</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span>      range.location = 17;</pre><pre><span class="lnum">   4:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   5:  </span>      range.length = 4;</pre><pre><span class="lnum">   6:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   7:  </span>  2.NSRange range = {17,4};</pre><pre><span class="lnum">   8:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   9:  </span>  3.NSRange range = NSMakeRange(17,4);</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>2.<strong>NSPoint NSSize NSRect</strong> 
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>typedef <span class="kwrd">struct</span> _NSPoint</pre><pre><span class="lnum">   2:  </span>{</pre><pre class="alt"><span class="lnum">   3:  </span>  <span class="kwrd">float</span> x;</pre><pre><span class="lnum">   4:  </span>  <span class="kwrd">float</span> y;</pre><pre class="alt"><span class="lnum">   5:  </span>}NSPoint;</pre><pre><span class="lnum">   6:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   7:  </span>typedef <span class="kwrd">struct</span> _NSSize</pre><pre><span class="lnum">   8:  </span>{</pre><pre class="alt"><span class="lnum">   9:  </span>  <span class="kwrd">float</span> width;</pre><pre><span class="lnum">  10:  </span>  <span class="kwrd">float</span> height;</pre><pre class="alt"><span class="lnum">  11:  </span>}NSSize;</pre><pre><span class="lnum">  12:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  13:  </span>typedef <span class="kwrd">struct</span> _NSRect</pre><pre><span class="lnum">  14:  </span>{</pre><pre class="alt"><span class="lnum">  15:  </span>  NSPoint origin;</pre><pre><span class="lnum">  16:  </span>  NSSize size;</pre><pre class="alt"><span class="lnum">  17:  </span>}NSRect;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>创建方法:NSMakePoint();NSMakeSize();NSMakeRect(); 
<p>//以上几个数据类型不是对象而是struct，原因是因为满足性能需求。 
<p>3.<strong>NSString NSMutableString</strong> 
<p>创建方法: 
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>+ (id)stringWithFormat:(NSString *)format, ...</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span>NSString *height;</pre><pre><span class="lnum">   4:  </span>height = [NSString initWithFormat:<span class="str">@"Your height is %d feet"</span>,5];</pre><pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>创建方法: 
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>NSMutableString *<span class="kwrd">string</span>;</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">string</span> = [NSMutableString stringWithCapacity:42];</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>4.<strong>NSArray NSMutableArray</strong> 
<p>用来存储Objective-C的对象，而不能存储C语言中的基本数据类型. 
<p>创建方法: 
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>+ (id)arrayWithObjects:(id)firstObj, ...</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span>NSArray *array;</pre><pre><span class="lnum">   4:  </span>array = [NSArray arrayWithObjects:<span class="str">@"one"</span>,<span class="str">@"two"</span>,<span class="str">@"three"</span>,nil];</pre>
<h6><font size="3" face="微软雅黑"><font style="font-weight: bold">5.NSEnumerator(<font style="font-weight: normal">Tiger系统</font>)</font></font></h6>
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>NSEnumerator *enumerator</pre><pre><span class="lnum">   2:  </span>enumerator = [array objectEnumerator];</pre><pre class="alt"><span class="lnum">   3:  </span>&nbsp;</pre><pre><span class="lnum">   4:  </span>id thingie;</pre><pre class="alt"><span class="lnum">   5:  </span><span class="kwrd">while</span>(thingie = [enumerator nextObject])</pre><pre><span class="lnum">   6:  </span>{</pre><pre class="alt"><span class="lnum">   7:  </span>    NSLog(<span class="str">@"i found %@"</span>,thingie);</pre><pre><span class="lnum">   8:  </span>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</div>
<div class="csharpcode"><em><font size="3">5.1快速枚举</font></em></div>
<div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">for</span>(NSString *<span class="kwrd">string</span> <span class="kwrd">in</span> array)</pre><pre><span class="lnum">   2:  </span>{</pre><pre class="alt"><span class="lnum">   3:  </span>    NSLog(<span class="str">@"i found %@"</span>,<span class="kwrd">string</span>);</pre><pre><span class="lnum">   4:  </span>}</pre></div>
<p><strong>6.NSDictionary</strong></p>
<p>创建方法：</p>
<div class="csharpcode"><pre class="alt">+(id)dictionaryWithObjectAndKeys:(id)fristObject,...;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>添加元素：</p>
<div class="csharpcode"><pre class="alt">-(<span class="kwrd">void</span>)setObject:(id)anObject forkey:(id)akey;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p><em><font size="3" face="Consolas"></font></em>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
<p>(fuck!!写到这，windows live writer报错，后面写的都没保存…)</p>
<p><strong>7.NSNumber</strong></p>
<p><strong>8.NSValue</strong></p>
<p><strong>9.NSNull</strong></p><img src ="http://www.cppblog.com/cokecoffe/aggbug/172345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-04-22 16:58 <a href="http://www.cppblog.com/cokecoffe/archive/2012/04/22/172345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OS X Terminal字体颜色设置</title><link>http://www.cppblog.com/cokecoffe/archive/2012/04/13/171296.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Fri, 13 Apr 2012 15:28:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/04/13/171296.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/171296.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/04/13/171296.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/171296.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/171296.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: OS X 默认终端默认白底黑字，看起来不大舒服，于是想换下字体颜色，按照文件类型来显示不同的颜色：在 ~ 先建立一个文件  ~/.bash_profile 加入下面的两行：export CLICOLOR=1export LSCOLORS=gxfxaxdxcxegedabagacad存盘， 退出Terminal, 重起Terminal.更改LSCOLORS可以有不同的颜色效果。 --------...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/04/13/171296.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/171296.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-04-13 23:28 <a href="http://www.cppblog.com/cokecoffe/archive/2012/04/13/171296.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NSArray Sort</title><link>http://www.cppblog.com/cokecoffe/archive/2012/04/05/170180.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Thu, 05 Apr 2012 09:09:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/04/05/170180.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/170180.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/04/05/170180.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/170180.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/170180.html</trackback:ping><description><![CDATA[<h3 class="tasks" style="margin-top: 0.471em; margin-bottom: 0.25em; font-size: 19px; font-weight: normal; color: #000000;">Sorting</h3>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayHint">– sortedArrayHint</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context:">– sortedArrayUsingFunction:context:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context:hint:">– sortedArrayUsingFunction:context:hint:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingDescriptors:">– sortedArrayUsingDescriptors:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingSelector:">– sortedArrayUsingSelector:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingComparator:">– sortedArrayUsingComparator:</a></code></span></li>
<li style="margin-top: 0.167em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span class="tooltip"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayWithOptions:usingComparator:">– sortedArrayWithOptions:usingComparator:</a></code></span></li>
</ul>
<p> </p>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
- (NSArray *)sortedArrayUsingSelector:(SEL)<em style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; font-style: italic;">comparator</em>
</ul>
<h5 style="margin-top: 0.692em; margin-bottom: 0.154em; font-size: 13px; color: #000000; margin-right: 0px; margin-left: 0px; padding: 0px;">Parameters</h5>
<dl class="termdef" style="margin-top: 0px; margin-bottom: 0.833em;"><dt style="clear: both; margin-top: 0px;"><em style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; font-style: italic;"> comparator</em></dt><dd style="margin-left: 1.25em; margin-top: 0.083em; margin-bottom: 0.5em;">
<p style="margin-top: -0.083em; margin-bottom: 0.5em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;">A selector that identifies the method to use to compare two elements at a time. The method should return<code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedAscending">NSOrderedAscending</a></code> if the receiving array is smaller than the argument, <code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedDescending">NSOrderedDescending</a></code> if the receiving array is larger than the argument, and <code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedSame">NSOrderedSame</a></code> if they are equal.</p>
<p style="margin-top: -0.083em; margin-bottom: 0.5em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;">//selector定义了一个比较两个数组元素的方法，如果此方法返回<code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedAscending">NSOrderedAscending</a>说明此元素比参数元素小，如果返回<code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: #666666;"><a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedDescending">NSOrderedDescendin</a>g说明接收的数组元素比参数元素大，<a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSOrderedSame">NSOrderedSame</a>相等。</code></code></p>
</dd></dl>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
<span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;"><span style="font-size: 13px;"><em>Example:</em></span></span>
</ul>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
<span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;"><span style="font-size: 13px;"><em>一个元素为NSString的数组可以通过调用NSString类中的<a style="color: #3366cc; text-decoration: none;" href="file:///Users/Escaton/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_1.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/caseInsensitiveCompare:" target="_self">caseInsensitiveCompare:</a>方法作为Selector。</em></span></span>
</ul>
<ul class="tooltip" style="list-style-type: none; list-style-position: outside; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 0px; white-space: nowrap;">
<span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif;"><span style="font-size: 13px;"><em>假设anArray已经存在：</em></span></span>
</ul>
<table style="width: 802px; background-color: #f1f5f9; border-collapse: collapse; padding-bottom: 4px; border: 1px solid #c7cfd5;">
<tbody>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin-top: -0.083em; margin-bottom: 0px; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; margin-right: 0.333em; margin-left: 0.5em; line-height: 13px; white-space: pre-wrap;"> NSArray *sortedArray =</pre>
</td>
</tr>
<tr style="border-bottom-width: 0px; border-bottom-style: solid; border-bottom-color: #ffffff;">
<td style="padding: 0.5em;" scope="row">
<pre style="margin-top: -0.083em; margin-bottom: 0px; font-size: 12px; font-family: Courier, Consolas, monospace; color: #666666; margin-right: 0.333em; margin-left: 0.5em; line-height: 13px; white-space: pre-wrap;">         [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];</pre>
</td>
</tr>
</tbody>
</table><img src ="http://www.cppblog.com/cokecoffe/aggbug/170180.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-04-05 17:09 <a href="http://www.cppblog.com/cokecoffe/archive/2012/04/05/170180.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何在多台机器上共享IOS证书</title><link>http://www.cppblog.com/cokecoffe/archive/2012/03/13/167765.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Tue, 13 Mar 2012 03:01:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/03/13/167765.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/167765.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/03/13/167765.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/167765.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/167765.html</trackback:ping><description><![CDATA[<p><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1. 下载.cer文件到别的机器。就是在IDP上的那个。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2. 从发送申请文件（certificate Request，后缀名为certSigningRequest）的机器上把证书对应的private key（.p12文件）导出，密码自己定，要记住，后面导入的时候要用。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">3. 在你需要的机器上安装证书（.cer），导入私钥文件(.p12)。安装对应App的provisioning profile。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">4. Over，你可以用其他机器开发了。</span></p>
<p><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><br /></span></p>
<p>注：必须得从申请机器上导出private key.到其他机器上</p>
<p><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">一、成员介绍</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>1.    Certification(证书)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">证书是对电脑开发资格的认证，每个开发者帐号有一套，分为两种：</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1)    Developer Certification(开发证书)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安装在电脑上提供权限：开发人员通过设备进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">可以生成副本供多台电脑安装；</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2)      Distribution Certification(发布证书)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安装在电脑上提供发布iOS程序的权限：开发人员可以制做测试版和发布版的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">不可生成副本，仅有配置该证书的电脑才可使用；（副本制做介绍在下面Keychain中介绍）</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>2.    Provisioning Profile(授权文件)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">授权文件是对设备如iPod Touch、iPad、iPhone的授权，文件内记录的是设备的UDID和程序的App Id，即使被授权的设备可以安装或调试Bundle identifier与授权文件中记录的App Id对应的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">开发者帐号在创建授权文件时候会选择App Id，（开发者帐号下App Id中添加，单选）和UDID（开发者帐号下Devices中添加最多100个，多选）。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">授权文件分为两种，对应相应的证书使用：</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1)    Developer Provisioning Profile(开发授权文件)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">在装有开发证书或副本的电脑上使用，开发人员选择该授权文件通过电脑将程序安装到授权文件记录的设备中，即可进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">注意：确保电脑有权限真机调试，即安装了开发证书或副本；在开发工具中程序的Bundle identifier和选中使用的授权文件的App Id要一致；连接调试的设备的UDID在选中的授权文件中有记录。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2)    Distribution Provisioning Profile(发布授权文件)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">在装有发布证书的电脑上（即配置证书的电脑，只有一台）制做测试版和发布版的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">发布版就是发布到App Store上的程序文件，开发者帐号创建授权文件时选择store选项，选择App Id，无需选择UDID；</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">测试版就是在发布之前交给测试人员可同步到设备上的程序文件，开发者帐号创建授权文件时选择AdHoc，选择App Id和UDID；只有选中的UDID对应的设备才可能安装上通过该授权文件制做的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>3.    Keychain(开发密钥)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安装证书成功的情况下证书下都会生成Keychain，上面提到的证书副本就是通过配置证书的电脑导出Keychain（就是.p12文件）安装到其他机子上，让其他机子得到证书对应的权限。Developer Certification就可以制做副本Keychain分发到其他电脑上安装，使其可以进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">注意：Distribution Certification只有配置证书的电脑才可使用，因此即使导出导出Keychain安装到其他电脑上，其他电脑也不可能具有证书的权限。</span></p><img src ="http://www.cppblog.com/cokecoffe/aggbug/167765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-03-13 11:01 <a href="http://www.cppblog.com/cokecoffe/archive/2012/03/13/167765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS中编码转换方法(转）</title><link>http://www.cppblog.com/cokecoffe/archive/2012/02/06/165031.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Mon, 06 Feb 2012 03:18:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/02/06/165031.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/165031.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/02/06/165031.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/165031.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/165031.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: IOS开发中编码转换方法是本文要介绍的内容，主要是来学习一下编码转换的内容，不多说，直接来看详细内容。我们可以使用以下方法进行编码转换。NSString*&nbsp;str2&nbsp;=&nbsp;[NSString&nbsp;stringWithCString:str1&nbsp;encoding:enc1];&nbsp;再调用NSString的cStringUsingEncoding:enc...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/02/06/165031.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/165031.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-02-06 11:18 <a href="http://www.cppblog.com/cokecoffe/archive/2012/02/06/165031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Objective-C 属性参数</title><link>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164960.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 04 Feb 2012 15:09:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164960.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/164960.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164960.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/164960.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/164960.html</trackback:ping><description><![CDATA[<h4>属性参数有以下三种Writability、Setter、Semantics&nbsp;Atomicity<br /><br />Writability<br /></h4><hr /><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">These attributes specify whether or not a property has an associated set accessor. They are mutually exclusive.<br /></p><div><span style="color: #666666; font-family: Courier, Consolas, monospace; background-color: #ffffff; ">readwrite&nbsp;</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">Indicates that the property should be treated as read/write. This attribute is the default.</span><div><div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-size: 13px; line-height: normal; background-color: #ffffff; ">readonly&nbsp;</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 10pt; ">&nbsp;If you use the&nbsp;</span><code style="font-family: Courier, Consolas, monospace; "><span style="font-size: 10pt; ">@synthesize</span></code><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 10pt; ">&nbsp;directive in the implementation block, only the getter method is synthesized. Moreover, if you attempt to assign a value using the dot syntax, you get a compiler error.</span></div><div><h4>Setter Semantics<br /><hr /><br /><div><span style="font-weight: normal; background-color: #ffffff; ">These attributes specify the semantics of a set accessor. They are mutually exclusive.</span></div><div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-weight: normal; background-color: #ffffff; ">strong<br />weak<br /></span><div><dt style="clear: both; margin-top: 0px; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; "><code style="font-family: Courier, Consolas, monospace; color: #666666; ">copy&nbsp;&nbsp;&nbsp;&nbsp;</code><span style="font-weight: normal;">Specifies that a copy of the object should be used for assignment.The previous value is sent a&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; "><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/release" target="_self" style="color: #003366; text-decoration: none; ">release</a></code>&nbsp;message.The copy is made by invoking the&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; "><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/copy" target="_self" style="color: #003366; text-decoration: none; ">copy<br /></a></code>&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; ">method. This attribute is valid only for object types, which must implement the&nbsp;</span><code style="font-weight: normal; font-family: Courier, Consolas, monospace; color: #666666; ">NSCopying</code><span style="font-weight: normal; ">&nbsp;&nbsp;</span><span data-header="Protocol" data-contents="A protocol declares a programmatic interface that any class may choose to implement. " style="font-weight: normal; color: #3366cc; text-decoration: none; border-bottom-width: 1px; border-bottom-style: dashed; border-bottom-color: #3366cc; white-space: nowrap; cursor: pointer; -webkit-transition-property: color, background-color, border-bottom, border-top-left-radius, border-top-right-radius, padding, margin; -webkit-transition-duration: 0.25s; "><a target="_self" data-href="../../../../General/Conceptual/DevPedia-CocoaCore/Protocol.html#//apple_ref/doc/uid/TP40008195-CH45" style="text-decoration: none; ">protocol</a></span><span style="font-weight: normal; ">.<br /></span><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; background-color: #ffffff; ">指定应该使用对象的副本（深度复制），前一个值发送一条release消息。基本上像retain，但是没有增加引用计数，是分配一块新的内<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;存来放置它。<br /><br /></span></div></dt></div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-weight: normal; background-color: #ffffff; ">assgin&nbsp;</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: normal; font-size: 10pt; font-weight: normal;">Specifies that the setter uses simple assignment. This attribute is the default.</span><span style="font-weight: normal;"><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: normal; font-size: 10pt; ">&nbsp;</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 10pt; line-height: normal; ">You use this attribute for scalar types such as&nbsp;</span><code style="font-size: 13px; line-height: normal; font-family: Courier, Consolas, monospace; color: #666666; "><span style="font-size: 10pt; ">NSInteger</span></code><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 10pt; line-height: normal; ">&nbsp;and&nbsp;</span><code style="font-size: 13px; line-height: normal; font-family: Courier, Consolas, monospace; color: #666666; "><span style="font-size: 10pt; ">CGRect</span></code><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 10pt; line-height: normal; ">.<br /></span></span><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #444444; font-family: 宋体, verdana, helvetica, sans-serif; background-color: #ffffff; ">setter方法直接赋值，而不进行retain操作，比如NSInteger和CGRect，它们不是对象，所以不用release。<br /><br /></span></div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-weight: normal; background-color: #ffffff; ">retain&nbsp;</span><span style="font-weight: normal;"><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">Specifies that&nbsp;</span><code style="font-size: 13px; line-height: normal; font-family: Courier, Consolas, monospace; color: #666666; "><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/retain" target="_self" style="color: #003366; text-decoration: none; ">retain</a></code><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">&nbsp;should be invoked on the object upon assignment.</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">The previous value is sent a&nbsp;</span><code style="font-size: 13px; line-height: normal; font-family: Courier, Consolas, monospace; color: #666666; "><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/release" target="_self" style="color: #003366; text-decoration: none; ">release</a></code><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">&nbsp;message.<br /></span></span><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #444444; font-family: 宋体, verdana, helvetica, sans-serif; background-color: #ffffff; ">setter方法对参数进行release旧值，再retain新值 例如：</span>&nbsp; &nbsp;&nbsp;</div><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; ">　 &nbsp; &nbsp;&nbsp;1.-(<span style="color: #0000ff; ">void</span>)&nbsp;setObj:(ClassX*)&nbsp;value<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.{<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(obj&nbsp;!=&nbsp;value)<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[obj&nbsp;release];<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj&nbsp;=&nbsp;[value&nbsp;retain];<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8.}</div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-weight: normal; background-color: #ffffff; "><br /></span><div><h4>Atomicity<br /><hr /><br /><div><span style="font-weight: normal; background-color: #ffffff; ">You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)</span></div><div><span style="color: #666666; font-family: Courier, Consolas, monospace; font-weight: normal; background-color: #ffffff; ">nonatomic</span><span style="font-weight: normal;"><span style="color: #666666; font-family: Courier, Consolas, monospace; background-color: #ffffff; ">&nbsp;</span><span style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">Specifies that accessors are nonatomic.&nbsp;</span><em style="font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; ">By default, accessors are atomic.</em></span></div></h4></div></div></h4></div></div></div><p>&nbsp;</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/164960.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-02-04 23:09 <a href="http://www.cppblog.com/cokecoffe/archive/2012/02/04/164960.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NSDictionary</title><link>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164957.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 04 Feb 2012 14:16:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164957.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/164957.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/02/04/164957.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/164957.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/164957.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: The&nbsp;NSDictionary&nbsp;class declares the programmatic interface to objects that manage immutable associations of keys and values.NSDictionary类定义了对于objects的接口，用于将键值和数值关联起来。Use this class or its su...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/02/04/164957.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/164957.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-02-04 22:16 <a href="http://www.cppblog.com/cokecoffe/archive/2012/02/04/164957.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NSRange用法（转）</title><link>http://www.cppblog.com/cokecoffe/archive/2012/01/31/164722.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Tue, 31 Jan 2012 07:15:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/01/31/164722.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/164722.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/01/31/164722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/164722.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/164722.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: NSRange的定义typedef&nbsp;struct&nbsp;_NSRange{&nbsp;&nbsp;NSUInteger&nbsp;location;&nbsp;&nbsp;NSUInteger&nbsp;length;}&nbsp;NSRange;&nbsp;NSRange是一个结构体，其中location是一个以0为开始的index，length是表示对...&nbsp;&nbsp;<a href='http://www.cppblog.com/cokecoffe/archive/2012/01/31/164722.html'>阅读全文</a><img src ="http://www.cppblog.com/cokecoffe/aggbug/164722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2012-01-31 15:15 <a href="http://www.cppblog.com/cokecoffe/archive/2012/01/31/164722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nonatomic</title><link>http://www.cppblog.com/cokecoffe/archive/2011/11/30/161243.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 30 Nov 2011 11:51:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2011/11/30/161243.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/161243.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2011/11/30/161243.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/161243.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/161243.html</trackback:ping><description><![CDATA[<div><span style="font-family: 'Comic Sans MS'; ">它要与@synthesize一起使用才有意义.</span><br /><span style="font-family: 'Comic Sans MS'; ">atomic的意思就是setter/getter这个函数是一个原语操作。如果有多个线程同时调用setter的话，不会出现某一个线程执行setter全部语句之前，另一个线程开始执行setter情况，相当于函数头尾加了锁一样.</span><br /><span style="font-family: 'Comic Sans MS'; ">nonatomic不保证setter/getter的原语行，所以你可能会取到不完整的东西。 比如setter函数里面改变两个成员变量，如果你用nonatomic的话，getter可能会取到只更改了其中一个变量时候的状态 .</span></div><img src ="http://www.cppblog.com/cokecoffe/aggbug/161243.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2011-11-30 19:51 <a href="http://www.cppblog.com/cokecoffe/archive/2011/11/30/161243.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Target failed to run: Remote exception encountered: 'Failed to get task for pid #</title><link>http://www.cppblog.com/cokecoffe/archive/2011/11/16/160279.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 16 Nov 2011 09:23:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2011/11/16/160279.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/160279.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2011/11/16/160279.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/160279.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/160279.html</trackback:ping><description><![CDATA[I got this error just recently when i tried to use the instrument to profile my iPad application on the device. And when i selected "Profile" from the menu, and instrument was opened. Then i selected "Allocations" or "Leaks", i just heard "Funk" and then nothing happened. So i checked out the Console and found out some errors about missing plug-ins for these selected functions. So bascially, it's because some plug-in in your Xcode application folder was missing or crrupt. So better remove Xcode completely through Command line "sudo /Developer/Library/uninstall-devtools --mode=all",then reinstall it. You should be good to go.  <br />Then when i rerun my app with instrument i received another error which was the topic of this post. After searching a little bit. It's actually very easy to fix.<br /><br />1.Make sure, the "Profile" scheme is using "debug" not "release" build configuration<br /><br />Here is the way how to change it: In Xcode4, select "Product/Edit Scheme" from the top menu then click on the "Profile" button on the left panel. Under the "Info" tab you will see "Build configuration", make sure "Debug" is selected.<img src ="http://www.cppblog.com/cokecoffe/aggbug/160279.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2011-11-16 17:23 <a href="http://www.cppblog.com/cokecoffe/archive/2011/11/16/160279.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL ES multithreading and EAGLSharegroup</title><link>http://www.cppblog.com/cokecoffe/archive/2011/11/15/160185.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Tue, 15 Nov 2011 09:36:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2011/11/15/160185.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/160185.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2011/11/15/160185.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/160185.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/160185.html</trackback:ping><description><![CDATA[<a href="http://developer.apple.com/library/ios/#qa/qa1612/_index.html">http://developer.apple.com/library/ios/#qa/qa1612/_index.html</a><div><div style="margin-top: 1em; margin-bottom: -0.5em; font: normal normal normal 190%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; color: #3c4c6c; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; ">Technical Q&amp;A QA1612</div><h1>OpenGL ES multithreading and EAGLSharegroup</h1><h2>Q:&nbsp; In my multithreading OpenGL ES application, I load textures (or vertices) on a secondary thread then draw them onto screen on the main thread. Occasionally I see blank images or application freezes. What could be causing this?</h2><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">A:&nbsp;In my multithreading OpenGL ES application, I load textures (or vertices) on a secondary thread then draw them onto screen on the main thread. Occasionally I see blank images or application freezes. What could be causing this?</p><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">It is very likely that the main and background threads are accessing the same OpenGL ES context simultaneously.</p><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">OpenGL ES commands for a specific context are not reentrant. You should never have more than one thread accessing a single context at the same time. It is highly recommended that you use only one thread per context.</p><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; "><strong style="font-weight: bold; ">Listing 1</strong>&nbsp;demonstrates how to create and make current a context&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">contextB</code>&nbsp;using the&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">sharegroup</code>&nbsp;property (an&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">EAGLSharegroup</code>&nbsp;object) obtained from another already-allocated context&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">contextA</code>. Such contexts that belong to the same sharegroup can share resources, for example, textures, FBOs, etc. So you may use&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">contextB</code>&nbsp;on the secondary thread to create textures, and&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">contextA</code>&nbsp;on the main thread to draw the textures onto screen.</p><br /><p clear"="" style="margin-top: 1.667em; margin-bottom: -0.85em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; clear: both; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; "><strong style="font-weight: bold; ">Listing 1</strong>&nbsp;&nbsp;Creating a context belonging to the same sharegroup<br /><br /></p><div style="background-color: #eeeeee; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; 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 />-->contextB&nbsp;=&nbsp;[[EAGLContext&nbsp;alloc]&nbsp;initWithAPI:kEAGLRenderingAPIOpenGLES1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sharegroup:contextA.sharegroup];&nbsp;<br /><span style="color: #0000FF; ">if</span>&nbsp;(!contextB&nbsp;||&nbsp;![EAGLContext&nbsp;setCurrentContext:contextB])&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Handle&nbsp;errors&nbsp;here&nbsp;</span><span style="color: #008000; "><br /></span>}</div><p>&nbsp;</p><div clear"="" style="clear: both; margin-top: 1.5em; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; "></div><div clear"="" style="clear: both; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #5088c5; border-right-color: #5088c5; border-bottom-color: #5088c5; border-left-color: #5088c5; margin-top: 1.667em; margin-right: 0px; margin-bottom: 1.75em; margin-left: 0px; padding-right: 0.667em; padding-bottom: 0.083em; padding-left: 0.75em; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; "><aside><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="line-height: normal; "><br /></span></font><p style="font-size: 13px; margin-top: 0.583em; margin-bottom: 0px; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; "><strong style="font-weight: bold; ">Important:</strong>&nbsp;The only way to get a valid&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">EAGLSharegroup</code>&nbsp;object is to query it from an existing&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">EAGLContext</code>&nbsp;object. Any other method, such as explicitly creating it, will result in crashes or undefined behavior.</p><p style="font-size: 13px; margin-top: 0.583em; margin-bottom: 0px; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; "></p></aside></div><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">When you want to modify a resource on one context, you must first make sure it is not currently in use on another, even if you are accessing them from different threads. Once you modify it, its state is undefined until flushing and binding the object have been completed. You should never use an undefined object, whether you access it from a different context or not.</p><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">Take a texture as an example.&nbsp;<strong style="font-weight: bold; ">Listing 2</strong>&nbsp;shows the correct way to deal with multiple contexts. Any other ordering will not ensure consistent and correct behavior. It may result in data corruption, leaks, or crashes otherwise.<br /><br /><div><p clear"="" style="margin-top: 1.667em; margin-bottom: -0.85em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; clear: both; "><strong style="font-weight: bold; ">Listing 2</strong>&nbsp;&nbsp;Modifying a texture on context B prior to using it on context A<br /></p></div><div></div></p><div style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><font class="Apple-style-span" face="'Lucida Grande', Geneva, Helvetica, Arial, sans-serif" size="2"><span class="Apple-style-span" style="line-height: normal; "><strong><br /></strong></span></font><font class="Apple-style-span" color="#008000">//</font><span style="color: #008000; ">&nbsp;1.&nbsp;Ensure&nbsp;context&nbsp;A&nbsp;is&nbsp;not&nbsp;bound&nbsp;to&nbsp;the&nbsp;texture</span><span style="color: #008000; "><br /></span>&nbsp;[EAGLContext&nbsp;setCurrentContext:contextA];<br />&nbsp;glBindTexture(GL_TEXTURE_2D,&nbsp;0);&nbsp;&nbsp;<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;2.&nbsp;Call&nbsp;flush&nbsp;on&nbsp;context&nbsp;A&nbsp;&nbsp;</span><span style="color: #008000; "><br /></span>glFlush();&nbsp;&nbsp;&nbsp;<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;3.&nbsp;Modify&nbsp;the&nbsp;texture&nbsp;on&nbsp;context&nbsp;B&nbsp;</span><span style="color: #008000; "><br /></span>[EAGLContext&nbsp;setCurrentContext:contextB];&nbsp;<br />glBindTexture(GL_TEXTURE_2D,&nbsp;texId);&nbsp;<br /><br />&nbsp;<span style="color: #008000; ">//<br /></span>&nbsp;Modify&nbsp;the&nbsp;texture&nbsp;data&nbsp;here<br />&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; "><br /><br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;4.&nbsp;Call&nbsp;flush&nbsp;on&nbsp;context&nbsp;B&nbsp;</span><span style="color: #008000; "><br /></span>glFlush();&nbsp;&nbsp;<br />&nbsp;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;5.&nbsp;Rebind&nbsp;the&nbsp;texture&nbsp;on&nbsp;context&nbsp;A&nbsp;</span><span style="color: #008000; "><br /></span>[EAGLContext&nbsp;setCurrentContext:contextA];<br />&nbsp;glBindTexture(GL_TEXTURE_2D,&nbsp;texId);&nbsp;<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;6.&nbsp;Use&nbsp;the&nbsp;texture&nbsp;as&nbsp;normal&nbsp;on&nbsp;context&nbsp;A</span></div><p>&nbsp;</p><div clear"="" style="clear: both; margin-top: 1.5em; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; "></div><p style="margin-top: 0px; margin-bottom: 0.833em; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; ">For more information on the&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">EAGLContext/-initWithAPI:sharegroup:</code>&nbsp;API and the&nbsp;<code style="font-family: Courier, Consolas, monospace; color: #666666; ">sharegroup</code>&nbsp;property, see the&nbsp;<span style="margin-top: 0px; font: normal normal normal 100%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; margin-bottom: 0.833em; padding-bottom: 0.833em; vertical-align: top; "><a href="http://developer.apple.com/iphone/library/documentation/OpenGLES/Reference/EAGLContext_ClassRef/Reference/EAGLContext.html" target="_top" style="color: #3366cc; ">EAGLContext Class Reference</a></span>.</p></div><div></div><img src ="http://www.cppblog.com/cokecoffe/aggbug/160185.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2011-11-15 17:36 <a href="http://www.cppblog.com/cokecoffe/archive/2011/11/15/160185.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Iphone SDK 获得当前连接的SSID等信息</title><link>http://www.cppblog.com/cokecoffe/archive/2011/10/11/158088.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Tue, 11 Oct 2011 15:03:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2011/10/11/158088.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/158088.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2011/10/11/158088.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/158088.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/158088.html</trackback:ping><description><![CDATA[&nbsp; &nbsp; 今天测试提出新需求，要求Kpad软件启动后，默认绑定房间号是路由名称（SSID）的房台。<br />
&nbsp; &nbsp; 方法如下：1.获取到当前连接的SSID。<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.从服务器读取所有房台的信息，将房台号与获取的SSID进行比较，然后绑定此房台。<br />
<br />关于获取路由SSID的方法：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;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; ">-</span><span style="color: #000000; ">&nbsp;(id)fetchSSIDInfo<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;CFArrayRef&nbsp;&nbsp;ifs&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;CNCopySupportedInterfaces();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;CFDictionaryRef&nbsp;info&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(ifs,&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;NSLog(</span><span style="color: #000000; ">@"</span><span style="color: #000000; ">SSID:&nbsp;%@</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,(NSString&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)CFDictionaryGetValue&nbsp;(info,kCNNetworkInfoKeySSID&nbsp;));<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;[ifs&nbsp;release];<br />&nbsp;&nbsp;&nbsp;&nbsp;[info&nbsp;release];<br /><br />}<br /></span></div><img src ="http://www.cppblog.com/cokecoffe/aggbug/158088.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cokecoffe/" target="_blank">Wangkeke</a> 2011-10-11 23:03 <a href="http://www.cppblog.com/cokecoffe/archive/2011/10/11/158088.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>