﻿<?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++博客-厚积薄发，滴水穿石</title><link>http://www.cppblog.com/cokecoffe/</link><description>搬家到主站了:http://www.cnblogs.com/cokecoffe/</description><language>zh-cn</language><lastBuildDate>Thu, 23 Apr 2026 10:12:05 GMT</lastBuildDate><pubDate>Thu, 23 Apr 2026 10:12:05 GMT</pubDate><ttl>60</ttl><item><title>WebService 概述（转）</title><link>http://www.cppblog.com/cokecoffe/archive/2012/06/04/177527.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Mon, 04 Jun 2012 13:36:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/06/04/177527.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/177527.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/06/04/177527.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/177527.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/177527.html</trackback:ping><description><![CDATA[<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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><strong style="margin: 0px; padding: 0px; color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 12px; color: red;"><a style="margin: 0px; padding: 0px; color: #ff6600; text-decoration: none;" href="http://www.cnblogs.com/alexis/" target="_blank">Alexis</a></span></strong><span style="color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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="margin: 0px; padding: 0px; color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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><a style="margin: 0px; padding: 0px; color: #ff6600; text-decoration: none; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" href="http://www.cnblogs.com/alexis/" target="_blank">http://www.cnblogs.com/alexis/</a><span style="color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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="margin: 0px; padding: 0px; color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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;">关于作者：专注于Windows Phone 7、Silverlight、Web前端（jQuery）。</span><br style="margin: 0px; padding: 0px; color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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><strong style="margin: 0px; padding: 0px; color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><a style="margin: 0px; padding: 0px; color: #ff6600; text-decoration: none;" href="mailto:shuifengxu@gmail.com">shuifengxuATgmail.com </a></strong><span style="color: #000000; font-family: 微软雅黑; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; 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></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"> </p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; color: red;">Web Service的宗旨是创建不需要用户界面就能与其他应用程序交互的Web应用程序。</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">举例说明它的优点，假如你正在为一家股票投资公司创建网站，你并不需要把不同证劵交易所得数据库与自己的后台数据库进行整合，因为你的应用程序可以使用Web Service，并使用XML格式交换数据。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">Web Service是松耦合的，它与服务器端和客户端使用的操作系统、编程语言都无关。<span style="margin: 0px; padding: 0px; color: red;">假如你既拥有客户端又有服务器端的访问和管理权，这种情况更适合用.NET 的Remoting技术，而不是Web service。</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">创建Web Service必须保证的是，服务器端和客户端都要支持HTTP、SOAP（简单对象访问协议）和XML等行业标准协议。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"> </p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 24pt;">Web Service是如何工作的</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">Web Service允许两个程序之间交换XML文档。在这个架构的顶层，微软实现了一个远程过程调用（Remote Procedure Call，PRC）模型。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">Web Service架构包括以下特性：</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">1。WebServcie的服务器端和客户端应用程序都能够连接到互联网。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">2。用于进行通信的数据格式必须遵守相同的开放标准，并且在大多数情况下，这个标准几乎总是SOAP。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">3。客户端和服务器端的系统是松耦合的。即Web Service不关心客户端和服务器端所使用的操作系统、对象模型或者编程语言。只要Web Service和使用Web Service的应用程序都能够发送和接收遵守适当协议标准的消息即可。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">下图为Web Service流程的逻辑架构</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><img style="margin: 0px; padding: 0px; border: 0px;" src="http://images.cnblogs.com/cnblogs_com/alexis/WebService.jpg" border="0" alt="" /></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">如图所示，一个Web Service使用着会向Web Service发出一个调用请求。使用者会认为它通过Internet直接和Web Service进行交流，当然这实际上是个幻象。实际上，真正的调用由代理类完成。代理类对于Web Service使用者来说是一个本地类。代理会处理所有的负责的复杂架构，包括通过Internet发送请求道服务器、从web Service取回结果并呈现给Web Service使用者。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">由于代理类在之前已在消费程序中注册，所有一切工作才可以顺利进行。注册有开发消费程序的程序员完成。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"> </p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 18pt;">开发Web Service</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">开发Web Service的流程与开发网页的流程近乎一致：</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">1。所有构成网页和服务的源文件都是文本文件，它们可以使用任何文本编辑器创建和修改。而类文件可以在控制台命令行中通过命令工具进行编译。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">2。可以在vs2005及以上版本中创建网页和Web Service</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">3。网页和Web Service既可以使用代码隐藏模型，也可以使用内联编码（inline coding）模型。Web Service中不需要使用代码隐藏技术，因为Web Service并不包括任何可视化内容。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">4。网页和Web Service都充分利用了CLR和.NET Framework。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">.aspx文件用于定义网页，而.asmx文件用于定Web Service，我们可以吧Web Service想象成类，类中的一些方法通过Internet被暴露给客户端。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 18pt;">代理</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; color: red;">客户端应用程序如果使用Web Service，必须先创建一个代理</span>。代理是要调用的真正代码的替身，它负责在机器边界引导调用。在代理在客户端应用程序中注册后，客户端应用程序调用方法就如调用本地对象一样。代理接受该调用，并以适当格式封装调用，然后以SOAP请求发送调用到服务器。当服务器返回SOAP包给客户端后，代理会对包进行解密，并且如同从本地对象的方法返回数据一样将其返回给客户端应用程序。如下图所示：</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><img style="margin: 0px; padding: 0px; border: 0px;" src="http://images.cnblogs.com/cnblogs_com/alexis/WebService2.jpg" border="0" alt="" /></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 18pt;">协议与标准（HTTP、XML、SOAP）</span></p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 14pt;">HTTP</span>：TCP/IP协议的最上层是超文本传输协议（HTTP）。它是用于在网络之间使用服务器和浏览器实现通讯，主要包括在服务器和浏览器建立连接，并将HTML传输到客户端浏览器。当客户端向服务器发送HTTP请求后，服务器就开始处理请求。通常，会返回HTML页面，然后通过浏览器呈现。然而对Web Service而言，服务器返回的是SOAP消息，消息中包含了被调用的Web Service方法的返回数据。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">HTTP请求从请求的浏览器出传递名称和值到服务器，这种请求包括GET和POST两种。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">GET请求中，名称和值会被附加到url上，数据是未加密的。当所有需要传递的数据可以使用名称和值成对表示，而且只需要传递少量字段，字段长度较短时，比较适合GET请求。另外，如果不需考虑安全问题时，也可以使用GET。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">POST请求中，配对的名称和值是作为请求消息的一部分发送的。当有大量字段或者参数很长时，适合使用POST请求。从安全方面看，POST比GET更安全，因为POST请求可以被加密。和GET请求一样，POST请求无法传递复杂的数据类型（如类、结构体和DataSet）。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 14pt;">XML</span>：是有W3C公布的开放标准的一种描述数据的方法。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">XML和HTML十分类似。不同的是HTML使用的是预定义元素，这些元素规定了HTML在浏览器中如何显示，而XML的元素则是由开放人员自己定义的，所以几乎所有的数据都可以表示。制定XML的目的是为了使其成为一种平台无关、语言无关的标准。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">XML架构（Schema）是用于定义元素已经XML文档中或者许多XML之间元素与元素之间关联的文件。在架构中将指定元素名称和内容类型。HTML与XML的显著差别：大多数HTML读取器有很好的容错能力，而XML读取器则完全不同，所以XML文件的格式必须正确。另外，XML元素都是小写的。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="margin: 0px; padding: 0px; font-size: 14pt;">SOAP</span>：（simple object access protocol，简单对象访问协议）是一种用于控制数据交换的XML语法。它是简单的、轻量级的信息交换协议。SOAP消息有消息内容和一个或多个头模块组成，并且封装在SOAP envelope中。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">SOAP使用XML语法来格式化内容。在设计上，SOAP尽可能简单并且提供最小化的功能。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">SOAP不需HTTP的GET和POST，它不受“名称/值”对的限制，我们可以使用它来发送复杂的对象，包括DataSet、类和其他对象。</p>
<p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: #000000; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">SOAP的缺点：SOAP消息十分冗长，因此如果存在带宽或者传输性能的问题，建议使用POST或GET。</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/177527.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-04 21:36 <a href="http://www.cppblog.com/cokecoffe/archive/2012/06/04/177527.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><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>1</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>1</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>Subversion基础：概念、安装、配置和基本操作(转）</title><link>http://www.cppblog.com/cokecoffe/archive/2012/06/01/177030.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Fri, 01 Jun 2012 02:25:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/06/01/177030.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/177030.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/06/01/177030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/177030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/177030.html</trackback:ping><description><![CDATA[<p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; "></p><div>转自:http://www.uml.org.cn/pzgl/200902137.asp<br /></div>摘要：介绍了 Subversion 的基本概念。详细讲解了在Windows下如何安装 Subversion，如何配置一个基本的Subversion&nbsp;<a title="服务器" target="_blank" href="http://server.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">服务器</a>。<p>&nbsp;</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">目录</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">一、基本概念</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">1、什么是版本控制</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">2、什么是 Subversion</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">3、版本库(repository)</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">二、安装</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">1、准备工作</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">2、安装<a title="服务器" target="_blank" href="http://product.it168.com/files/0402search.shtml" style="text-decoration: none; color: #000000; cursor: pointer; ">服务器</a>端和客户端</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">3、建立版本库(Repository)</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">4、运行独立服务器</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">三、基本配置</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">1、配置用户和权限</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">2、初始化导入</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">四、基本操作流程</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">1、取出(check out)</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">2、存入(check in)/提交(commit)</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">------------------------------------------------------------------分 割 线---------------------------------------------------------------</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; "><strong>一、基本概念</strong></p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">1、什么是版本控制</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">简单点来说，版本控制就是数据仓库，它可以记录你对文件的每次更改。这样，就算你在昏天黑地的改了几个月后老板说不要了，还是按照过去那样，你也不会抓狂，简单的恢复版本操作就搞定一切。</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">2、什么是 Subversion</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">Subversion是一个自由/开源版本控制系统，它管理文件和目录可以超越时间。一组文件存放在中心版本库，这个版本库很像一个普通的文件服务器，只是它可以记录每一次文件和目录的修改，这便使你可以取得数据以前的版本，从而可以检查所作的更改。从这个方面看，许多人把版本控制系统当作一种&#8220;时间机器&#8221;。</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">Subversion可以通过<a title="网络" target="_blank" href="http://net.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">网络</a>访问它的版本库，从而使用户可以在不同的电脑上使用。一定程度上可以说，允许用户在各自的地方修改同一份数据是促进协作。进展可能非常的迅速，并没有一个所有的改变都会取得效果的通道，由于所有的工作都有历史版本，你不必担心由于失去某个通道而影响质量，如果存在不正确的改变，只要取消改变。</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">一些版本控制系统也是<a title="软件" target="_blank" href="http://software.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">软件</a>配置管理(SCM)系统，这种系统经过特定的精巧设计来管理源代码，有许多关于软件开发的特性&#8212;本身理解编程语言、或者提供构建程序的工具。然而，Subversion不是这样一个系统，它是一个通用系统，可以管理任何类型的文件集，对你这可能是源代码，对别人，可能是一个货物报价单或者是书稿，或者是电影剪辑等。</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">3、版本库(repository)</p><p style="text-indent: 12pt; font-family: 宋体; font-size: 12px; line-height: 20px; ">Subversion 的核心就是 repository ，中文翻译成&#8220;版本库&#8221;。就是位于服务器端，统一管理和储存数据的地方。</p><div style="font-family: 宋体; font-size: 12px; line-height: 20px; "><div><div><p style="text-indent: 12pt; "><strong>二、安装</strong></p><div><p style="text-indent: 12pt; ">Subversion的设计包括一个抽象的<a title="网络" target="_blank" href="http://net.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">网络</a>层，这意味着版本库可以通过各种<a title="服务器" target="_blank" href="http://server.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">服务器</a>进程访问。理论上讲，Subversion可以使用无限数量的网络协议实现，目前实践中存在着两种<a title="服务器" target="_blank" href="http://product.it168.com/files/0402search.shtml" style="text-decoration: none; color: #000000; cursor: pointer; ">服务器</a>。</p><p style="text-indent: 12pt; ">&#8226; SVNServer：svnserve 是一个小的(也叫轻型的)、独立服务器，使用自己定义的协议和客户端。(作者注：以下称这种服务器为&#8220;svnserver服务器&#8221;。)</p><p style="text-indent: 12pt; ">&#8226; ApacheSVN：Apache是最流行的web服务器，通过使用 mod_dav_svn 模块，Apache可以访问版本库，并且可以使客户端使用HTTP的扩展协议WebDAV/DeltaV进行访问。(作者注：以下称这种服务器为&#8220;ApacheSVN服务器&#8221;。)</p><p style="text-indent: 12pt; ">下面介绍 SVNServer 服务器的安装，ApacheSVN 服务器的安装使用请看我写的《Subversion高级应用：SVN的多种认证方式》。</p><p style="text-indent: 12pt; ">环境</p><p style="text-indent: 12pt; ">OS：Windows XP SP2</p><p style="text-indent: 12pt; ">Web：Apache 2.2.6</p><p style="text-indent: 12pt; ">SVN：svn-win32-1.4.6</p><p style="text-indent: 12pt; ">1、准备工作。</p><p style="text-indent: 12pt; ">(1)获取 Subversion 服务器程序。</p><p style="text-indent: 12pt; ">到官方网站(http://subversion.tigris.org/)下载最新的服务器安装程序。目前最新的是1.4.6版本，具体下载地址在：http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100&amp;expandFolder=8100&amp;folderID=91 ，注意找 for apache 2.2.x 版本的。</p><p style="text-indent: 12pt; ">(2)获取 TortoiseSVN 客户端程序。</p><p style="text-indent: 12pt; ">从官方网站 http://tortoisesvn.net/downloads 获取最新的 TortoiseSVN 。TortoiseSVN 是一个客户端程序，用来与 subvers 服务器端通讯。Subversion 自带一个客户端程序 svn.exe ,但 TortoiseSVN 更好操作，提高效率。</p><p style="text-indent: 12pt; ">2、安装服务器端和客户端</p><p style="text-indent: 12pt; ">首先安装 Apache 2.2.6 ，具体安装方法大家参考相关资料，或者参看我写的《Windows下安装Apache 2.2.x》。</p><p style="text-indent: 12pt; ">其次安装 Subversion(以下简称SVN)的服务器端和客户端。下载下来的服务器端是个 zip 压缩包，直接解压缩即可，比如我解压到 E:\subversion 。客户端安装文件是个 exe 可执行文件，直接运行按提示安装即可，客户端安装完成后提示重启。</p><p style="text-indent: 12pt; ">3、建立版本库(Repository)</p><p style="text-indent: 12pt; ">运行Subversion服务器需要首先要建立一个版本库(Repository)。版本库可以看作是服务器上集中存放和管理数据的地方。</p><p style="text-indent: 12pt; ">开始建立版本库。首先建立 e:\svn 空文件夹作为所有版本库的根目录。然后，进入命令行并切换到subversion的bin目录。输入如下命令：</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svnadmin create E:\svn\repos1</div><p style="text-indent: 12pt; ">此命令在 E:\svn 下建立一个版本库 repos1 。repos1 下面会自动生成一些文件夹和文件。</p><p style="text-indent: 12pt; ">我们也可以使用 TortoiseSVN 图形化的完成这一步：</p><p style="text-indent: 12pt; ">先建立空目录 E:\svn\repos1 ，注意一定是要空的。然后在 repos1 文件夹上&#8220;右键-&gt;TortoiseSVN-&gt;Create Repository here...&#8221;，然后可以选择版本库模式，这里使用默认的FSFS即可，然后就创建了一系列文件夹和文件，同命令行建立的一样。</p><p style="text-indent: 12pt; ">4、运行独立服务器</p><p style="text-indent: 12pt; ">此时 subversion 服务还没有开始，只是通过它的命令建立了版本库。继续在刚才的命令窗口输入：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svnserve.exe &#8211;daemon</div><p style="text-indent: 12pt; ">svnserve 将会在端口 3690 等待请求，--daemon(两个短横线)选项告诉 svnserve 以守护进程方式运行，这样在手动终止之前不会退出。注意不要关闭命令行窗口，关闭窗口会把 svnserve 停止。</p><p style="text-indent: 12pt; ">为了验证svnserve正常工作，使用TortoiseSVN -&gt; Repo-browser 来查看版本库。在弹出的 URL 对话框中输入：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svn://localhost/svn/repos1</div><p style="text-indent: 12pt; ">点 OK 按钮后就可以看见 repos1 版本库的目录树结构了，只不过这时 repos1 是个空库。</p><p style="text-indent: 12pt; ">你也可以使用--root选项设置根位置来限制服务器的访问目录，从而增加<a title="安全" target="_blank" href="http://safe.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">安全</a>性和节约输入svnserve URL的时间：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svnserve.exe --daemon --root drive:\path\to\repository</div><p style="text-indent: 12pt; ">以前面的测试作为例，svnserve 将会运行为：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svnserve.exe --daemon --root e:\svn</div><p style="text-indent: 12pt; ">然后TortoiseSVN中的版本库浏览器URL缩减为：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　svn://localhost/repos1</div></div></div></div></div><div style="font-family: 宋体; font-size: 12px; line-height: 20px; "><div><div><div><p style="text-indent: 12pt; "><strong>三、基本配置</strong></p><p style="text-indent: 12pt; ">SVNServer<a title="服务器" target="_blank" href="http://server.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">服务器</a>安装完成后，必须经过基本配置才能使用。</p><p style="text-indent: 12pt; ">1、配置用户和权限</p><p style="text-indent: 12pt; ">用文本编辑器打开E:\svn\repos1\conf目录，修改svnserve.conf：</p><p style="text-indent: 12pt; ">将：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　# password-db = passwd</div><p style="text-indent: 12pt; ">改为：&nbsp;</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　password-db = passwd</div><p style="text-indent: 12pt; ">即去掉前面的 # 注释符，注意前面不能有空格。</p><p style="text-indent: 12pt; ">然后修改同目录的passwd文件，增加一个帐号：</p><p style="text-indent: 12pt; ">将：</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">[users]<br /># harry = harryssecret<br /># sally = sallyssecret</div><p style="text-indent: 12pt; ">增加帐号：</p><div style="width: 825px; word-break: break-all; border: 0.5pt solid windowtext; padding: 4px 5.4pt; background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; ">　　[users]<br />　　#harry = harryssecret<br />　　#sally = sallyssecret<br />　　test = test</div><p style="text-indent: 12pt; ">2、初始化导入</p><p style="text-indent: 12pt; ">下面就是将我们的数据(项目)导入到这个版本库，以后就由版本库管理我们的数据。我们的任何改动都会被版本库记录下来，甚至我们自己丢失、改错数据时版本库也能帮我们找回数据。</p><p style="text-indent: 12pt; ">比如，我在 d:\wwwroot 下有个 guestbook 文件夹，里面存放的是我编写的留言簿程序。在此文件夹上&#8220;右键 -&gt; TortoiseSVN -&gt; Import...&#8221; ，在弹出对话框的&#8220;URL of repository&#8221;输入&#8220;svn://localhost/repos1/guestbook&#8221;。在&#8220;Import message&#8221;输入&#8220;导入整个留言簿&#8221;作为注释。</p><p style="text-indent: 12pt; ">点 OK 后要求输入帐号。我们在用户名和密码处都输入 test 。完成后 guestbook 中的内容全部导入到了 svn://localhost/svn/repos1/guestbook 。</p><p style="text-indent: 12pt; ">我们看到在 e:\svn\repos1 没有任何变化，连个 guestbook 文件夹都没有建立，唯一的变化就是e:\svn\repos1容量变大了。实际上我们源guestbook中的内容已经导入 repos1 版本库了，源 guestbook 文件夹可以删除了。</p><p style="text-indent: 12pt; ">需要注意的是，这一步操作可以完全在另一台安装了 TortoiseSVN 的客户机上进行。例如运行svnserve的主机的IP是133.96.121.22，则URL部分输入的内容就是&#8220;svn://133.96.121.22&#8221; 。</p><p style="text-indent: 12pt; "><strong>四、基本操作流程</strong></p><p style="text-indent: 12pt; ">1、取出(check out)</p><p style="text-indent: 12pt; ">取出版本库到一个工作拷贝：</p><p style="text-indent: 12pt; ">来到任意空目录下，比如在f分区建立一个空文件夹 f:\work 。&#8220;右键 -&gt; SVN Checkout&#8221;。在&#8220;URL of repository&#8221;中输入&#8220;svn://localhost/svn/repos1/guestbook&#8221;，这样我们就得到了一份 guestbook 中内容的工作拷贝。</p><p style="text-indent: 12pt; ">2、存入(check in)/提交(commit)</p><p style="text-indent: 12pt; ">在工作拷贝中作出修改并提交：</p><p style="text-indent: 12pt; ">在 guestbook 工作拷贝中随便打开一个文件，作出修改，然后&#8220;右键 -&gt; SVN Commit... &#8221;。这样我们就把修改提交到了版本库，版本库根据情况<a title="存储" target="_blank" href="http://storage.it168.com/" style="text-decoration: none; color: #000000; cursor: pointer; ">存储</a>我们提交的数据。</p><p style="text-indent: 12pt; ">在修改过的文件上&#8220;右键 -&gt; TortoiseSVN -&gt; Show Log&#8221; ，可以看到对这个文件所有的提交。在不同的 revision 条目上&#8220;右键 -&gt; Compare with working copy&#8221;，我们可以比较工作拷贝的文件和所选 revision 版本的区别。</p></div></div></div></div><img src ="http://www.cppblog.com/cokecoffe/aggbug/177030.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-01 10:25 <a href="http://www.cppblog.com/cokecoffe/archive/2012/06/01/177030.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>3</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/24/175954.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Wed, 23 May 2012 16:32:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/24/175954.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/175954.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/24/175954.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/175954.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/175954.html</trackback:ping><description><![CDATA[<p style="font-family: arial, nsimsun, sans-serif; margin: 0px; padding: 0.3em 5px 0.7em; font-size: 0.76em; color: #000000; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><span style="font-size: 13px;">linux下进程间通信的几种主要手段简介：</span></p>
<ol style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 5px; padding-bottom: 5px; font-size: 0.76em; color: #000000; font-family: STHeiti; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">管道（Pipe）及有名管道（named pipe）：管道可用于具有亲缘关系进程间的通信，有名管道克服了管道没有名字的限制，因此，除具有管道所具有的功能外，它还允许无亲缘关系进程间的通信；</span></li>
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">信号（Signal）：信号是比较复杂的通信方式，用于通知接受进程有某种事件发生，除了用于进程间通信外，进程还可以发送信号给进程本身；linux除了支持Unix早期信号语义函数sigal外，还支持语义符合Posix.1标准的信号函数sigaction（实际上，该函数是基于BSD的，BSD为了实现可靠信号机制，又能够统一对外接口，用sigaction函数重新实现了signal函数）；</span></li>
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">报文（Message）队列（消息队列）：消息队列是消息的链接表，包括Posix消息队列system V消息队列。有足够权限的进程可以向队列中添加消息，被赋予读权限的进程则可以读走队列中的消息。消息队列克服了信号承载信息量少，管道只能承载无格式字节流以及缓冲区大小受限等缺点。</span></li>
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">共享内存：使得多个进程可以访问同一块内存空间，是最快的可用IPC形式。是针对其他通信机制运行效率较低而设计的。往往与其它通信机制，如信号量结合使用，来达到进程间的同步及互斥。</span></li>
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">信号量（semaphore）：主要作为进程间以及同一进程不同线程之间的同步手段。</span></li>
<li style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 3px;"><span style="font-size: 13px;">套接口（Socket）：更为一般的进程间通信机制，可用于不同机器之间的进程间通信。起初是由Unix系统的BSD分支开发出来的，但现在一般可以移植到其它类Unix系统上：Linux和System V的变种都支持套接字。</span></li>
</ol><img src ="http://www.cppblog.com/cokecoffe/aggbug/175954.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-24 00:32 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/24/175954.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/11/174517.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Thu, 10 May 2012 17:55:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/11/174517.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/174517.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/11/174517.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/174517.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/174517.html</trackback:ping><description><![CDATA[<p style="line-height: normal;"><span style="line-height: normal; color: #ff0000;">一、一维数组作为输入参数：</span></p>
<p style="line-height: normal;">大家都知道，如果<span style="line-height: normal;">一维数组作为参数</span>的话，可以按如下方法来定义函数：</p>
<p style="line-height: normal;">int func(int *array);</p>
<p style="line-height: normal;">或者</p>
<p style="line-height: normal;">int func(int array[M]); 其中M是数组的大小。</p>
<p style="line-height: normal;"> </p>
<p style="line-height: normal;"><span style="line-height: normal; color: #ff0000;">二、二维数组作为输入参数：</span></p>
<p style="line-height: normal;">而如果<span style="line-height: normal;">输入参数是二维数组</span>的话，可以按如下方法定义：</p>
<p style="line-height: normal;"><span style="line-height: normal; color: #1f7099;">1. 直接以二维数组作为参数：</span></p>
<p style="line-height: normal;">int func(int array[M][N]);</p>
<p style="line-height: normal;">或者 int func(int array[][N]);</p>
<p style="line-height: normal;">也就是说，二维数组作为参数，可以省略第一维的大小，但不可以省略第二维的大小，因为编译器在寻址时是按p + i * N + j来对p[i][j]进行寻址的，所以第二维参数必须给出。</p>
<p style="line-height: normal;"><span style="line-height: normal; color: #1f7099;">2. 以二维指针作为参数：</span></p>
<p style="line-height: normal;">int func(int **array);</p>
<p style="line-height: normal;">我们可以定义二维指针，然后寻址时手工进行即可：*((int *)array + i * N + j)，前面的(int *)是强制转换成指针类型。</p><img src ="http://www.cppblog.com/cokecoffe/aggbug/174517.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-11 01:55 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/11/174517.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>几个弱智C题</title><link>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html</link><dc:creator>Wangkeke</dc:creator><author>Wangkeke</author><pubDate>Sat, 05 May 2012 12:00:00 GMT</pubDate><guid>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html</guid><wfw:comment>http://www.cppblog.com/cokecoffe/comments/173769.html</wfw:comment><comments>http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cokecoffe/comments/commentRss/173769.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cokecoffe/services/trackbacks/173769.html</trackback:ping><description><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;">从网上下了一个C的笔试题，发现附带的答案，不是错的，就是很初级的人写的，发现看了半天，没看懂！于是自己写了一下</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: STSong; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><span style="font-family: 'Trebuchet MS'; "><strong>1.给定一个字符串，输出本字符串中只出现一次并且最靠前的那个字符的位置？</strong></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><span style="font-family: 'Trebuchet MS'; "><strong><span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">比如</span>"abaccddeeef" <span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">则是</span>b<span style="font-family: STSong; font-style: normal; font-variant: normal; line-height: normal; font-size: 14px; ">，输出</span>2</strong></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;">int</span> find_char(<span style="color: #b933a1;">const</span> <span style="color: #b933a1;">char</span> *str)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">int</span> pos[<span style="color: #2934d5;">256</span>];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">const</span> <span style="color: #b933a1;">char</span> *p = str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">if</span>((!str)||!(*str))<span style="color: #008212;">//</span><span style="font: 13.0px 'Heiti SC Light'; color: #008212;">空指针或者空串</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">return</span> -<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #33595d;">memset</span>(pos,-<span style="color: #2934d5;">1</span>,<span style="color: #b933a1;">sizeof</span>(pos));</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px;">&nbsp;</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-variant: normal; font-weight: normal; line-height: normal; min-height: 15px; "><em>//遍历一遍，存下每个字母的位置，如果存过一次，就把位置设置为-2</em></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (*p)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> (pos[*p] == -<span style="color: #2934d5;">1</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos[*p] = p - str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">else</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos[*p] = -<span style="color: #2934d5;">2</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-variant: normal; font-weight: normal; line-height: normal; min-height: 15px; "><em>//遍历存储字母位置的数组，如果存有位置，则返回</em></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;p = str;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (*p)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> (pos[*p]&gt;=<span style="color: #2934d5;">0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">return</span> pos[*p];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp; &nbsp; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;"><br /></span></p>
<p style="font-family: Menlo; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">&nbsp; &nbsp;<span style="color: #b933a1;">return</span> -<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">}</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Menlo; font-size: 13px; font-style: normal; font-variant: normal; line-height: normal; "><strong>&nbsp;</strong></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: STSong; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; "><strong><span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span>，给定一个整数，问这个整数转成<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span>进制后，里面包含有多少个<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">1</span>？比如：<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">10</span>，二进制表示为，<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">1010</span>则，输出<span style="font-family: Times; font-size: 12px; font-style: normal; font-variant: normal; line-height: normal; ">2</span></strong></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;"><span style="color: #b933a1;">int</span> howmany(<span style="color: #b933a1;">int</span> x)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">int</span> count = <span style="color: #2934d5;">0</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">while</span> (x)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b933a1;">if</span> ((x&amp;<span style="color: #2934d5;">1</span>) == <span style="color: #2934d5;">1</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count++;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = x&gt;&gt;<span style="color: #2934d5;">1</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">&nbsp; &nbsp;<span style="color: #b933a1;">return</span> count;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo;">}</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px STSong;"><span style="font: 12.0px Times;"><br /></span></p><img src ="http://www.cppblog.com/cokecoffe/aggbug/173769.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 20:00 <a href="http://www.cppblog.com/cokecoffe/archive/2012/05/05/173769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>