<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_JesseZhao(赵光)</title><subtitle type="text">未曾清贫难成人,不经打击老天真。自古英雄出炼狱,从来富贵入凡尘。</subtitle><id>http://feed.cnblogs.com/blog/u/23423/rss</id><updated>2011-09-14T13:39:59Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><generator>feed.cnblogs.com</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/23423/rss"/><entry><id>http://www.cnblogs.com/jessezhao/archive/2011/09/14/2176452.html</id><title type="text">手机程序开发和测试关注点整理</title><summary type="text">最近公司要组建手机测试部门，总结一下自己3年多做手机开发的经验，都是零星的木有条例，希望有帮助。大家有其他好的可以留言，互相交流。手机做为受限设备，从受限角度来考虑，他是屏幕尺寸受限，计算能力受限，电力供应受限。手机程序与常规PC程序在测试的时候需要从上诉三个受限角度多考虑一下。一、屏幕尺寸受限屏幕比例尺寸不一样，分辨率也不尽相同，应该保证在各种手机上面界面可以完全呈现，不能出现按钮，列表被接触屏幕等影响用户使用的情况。选项不易超过1屏幕，最多1.5屏幕。如果太多的选项就要考虑分步骤，做成向导样子。太多的选项会让用户放弃使用，也极易出现错误。对于输入不方便的手机，这个缺点更会被放大。手机界面上</summary><published>2011-09-14T09:27:00Z</published><updated>2011-09-14T09:27:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2011/09/14/2176452.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2011/09/14/2176452.html"/><content type="html">&lt;p class="p1"&gt;最近公司要组建手机测试部门，总结一下自己3年多做手机开发的经验，都是零星的木有条例，希望有帮助。大家有其他好的可以留言，互相交流。&lt;/p&gt;&lt;p class="p1"&gt;手机做为受限设备，从受限角度来考虑，他是屏幕尺寸受限，计算能力受限，电力供应受限。手机程序与常规PC程序在测试的时候需要从上诉三个受限角度多考虑一下。&lt;/p&gt;&lt;p class="p1"&gt;一、屏幕尺寸受限&lt;/p&gt;&lt;ol class="ol1"&gt;&lt;li class="li1"&gt;屏幕比例尺寸不一样，分辨率也不尽相同，应该保证在各种手机上面界面可以完全呈现，不能出现按钮，列表被接触屏幕等影响用户使用的情况。&lt;/li&gt;&lt;li class="li1"&gt;选项不易超过1屏幕，最多1.5屏幕。如果太多的选项就要考虑分步骤，做成向导样子。太多的选项会让用户放弃使用，也极易出现错误。对于输入不方便的手机，这个缺点更会被放大。&lt;/li&gt;&lt;li class="li1"&gt;手机界面上面不易出现超过10项的下拉列表，因为太多项目的下拉列表用户选择困难，还有就是对性能要求太高。以前**做过一个wap网站，下拉列表有100多项，普通nokia手机直接死机。iphone可以下拉，但是选择起来是很不方便，直接可以放弃使用。&lt;/li&gt;&lt;li class="li1"&gt;输入框界面要考虑弹出键盘会不会盖住下面的输入框，会不会影响用户输入和下一步操作。&lt;/li&gt;&lt;li class="li1"&gt;界面上面的按钮位置安排是否合理，符不符合用户习惯，尤其一些太小的按钮用户无法触摸到或不易触摸到。&lt;/li&gt;&lt;li class="li1"&gt;对于项目超过20项的列表建议使用筛选的方式，搜索和选择配合才能达到最好的用户体验。&lt;/li&gt;&lt;/ol&gt;&lt;p class="p1"&gt;二、计算能力受限&lt;/p&gt;&lt;ol class="ol1"&gt;&lt;li class="li1"&gt;再测试的时候注意测试对大图片，大文件加载的时候会不会崩溃。很多程序再写的时候不考虑手机内存上限，4m的高分辨率图片不进行缩放到文件直接加载到内存，系统会崩溃。对于大的xml文件不能采用dom方式加载。&lt;/li&gt;&lt;li class="li1"&gt;对于查询出列表方式的测试，要测试当返回结果超过20条的时候系统是选择分页加载还是直接都加载到界面。如果是直接都加载到界面，当返回条目超过某一个限制的时候手机程序也是必须崩溃的。&lt;/li&gt;&lt;li class="li1"&gt;开发手机程序的时候要多考虑内存满的前提下的异常处理。可以先再手机上面开启多点程序，然后再打开咱们的程序，进行一些耗内存的操作（比如打开摄像头，图片缩放等操作）看看再内存异常的前提下程序做了如何的处理，会不会崩溃，会不会走向莫名异常。&lt;/li&gt;&lt;li class="li1"&gt;手机详情界面界面如果显示的内容超过一屏幕，而内存也没有特殊的操作，可以再内存拼接成html，然后用webview来加载。这样两个优点，一是可以自定义样式很漂亮，二是webview会帮我们处理好翻页，滚动，图片处理等操作，对本程序使用的内存也是一个节省。&lt;/li&gt;&lt;li class="li1"&gt;对于有轮询操作的，写代码的时候后用while(0)但是循环体内必须sleep一下来释放cpu片，不然手机的cpu会很高，手机会发热很严重。&lt;/li&gt;&lt;li class="li1"&gt;手机网络为非稳定性网络，再测试的时候建议用离线和移动网络都跑一边，不要使用wifi测试，那样测试不出来网络异常处理。所有与网络相关操作，再手机上面最少要重试2边保证其可用性。&lt;/li&gt;&lt;/ol&gt;&lt;p class="p1"&gt;三、电力供应受限&lt;/p&gt;&lt;ol class="ol1"&gt;&lt;li class="li1"&gt;手机开发基础缓存数据加载到内存，少进行磁盘io操作，节省驱动sd卡需要的电量。对于gps，wifi等耗电设备再不使用的时候要要用程序关掉。&lt;/li&gt;&lt;li class="li1"&gt;网络通讯如果是周期性质的建议内容越少越好，心跳包发个1就好。周期间隔不宜低于一分钟。如果实时性要求不高建议15分钟一次。&lt;/li&gt;&lt;li class="li1"&gt;手机程序费特殊性要求一般不可以明显增加系统耗电。再测试的时候可以试着玩改程序一个小时，看看电量下降多少。不能超过10%。还有一个有效的方法，就是再测试程序1-2小时发现手机电池很热（多台手机都热）说明系统设计有问题，对资源使用过多，要更总分析。&lt;/li&gt;&lt;/ol&gt;&lt;p class="p2"&gt;&lt;/p&gt;&lt;p class="p1"&gt;手机测试最根本的原则就是可用。比如随意操作不能崩溃，使用方便，能选择的绝对不让用户输入。把用户当成傻瓜，不要让用户考虑太多。现在基本没有用户愿意去看操作手册。还有公司的程序多于专用apn相关，需要通过专用apn切换访问内网。最近看了几个程序，发现很多接入点切换不正确，不能正常访问，而且最不靠谱的是再程序进入的时候切换到专用apn，但是退出的时候不切换回来。用户再退出咱们的程序后变不能上网了。这样的后果就是咱们的程序破坏了系统的可用性，这种都属于很严重的bug。&lt;/p&gt;&lt;p class="p2"&gt;&lt;/p&gt;&lt;p class="p2"&gt;&lt;/p&gt;&lt;p class="p2"&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/2176452.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2011/09/14/2176452.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2011/08/22/2148792.html</id><title type="text">startActivityForResult的疑问与探索</title><summary type="text">问题：我遇到一个问题，因为手机终端内存很小，我程序需要实现一个A activity 利用startActivityForResult调用系统摄像头，然后获取舌头的设置的图片，再A里面显示。但是遇到问题，因为内存小，A再调用起来系统摄像头之后被系统释放掉了，当系统摄像头调用后返回到A，但是这时候A重新被create出来，这样的话应该就无法获得摄像头返回的值了。解决方案：android:configChanges="orientation|keyboardHidden|navigation"将这个属性添加到activity配置文件里面去吧，manifest.xml中问题探究：可</summary><published>2011-08-21T16:37:00Z</published><updated>2011-08-21T16:37:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2011/08/22/2148792.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2011/08/22/2148792.html"/><content type="html">&lt;table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; table-layout: fixed; width: 757px;"&gt;&lt;tbody style="word-wrap: break-word;"&gt;&lt;tr style="word-wrap: break-word;"&gt;&lt;td class="t_f" id="postmessage_546018" style="word-wrap: break-word; font-size: 14px;"&gt;&lt;p&gt;问题：&lt;/p&gt;&lt;p&gt;我遇到一个问题，因为手机终端内存很小，我程序需要实现一个A activity 利用startActivityForResult调用系统摄像头，然后获取舌头的设置的图片，再A里面显示。但是遇到问题，因为内存小，A再调用起来系统摄像头之后被系统释放掉了，当系统摄像头调用后返回到A，但是这时候A重新被create出来，这样的话应该就无法获得摄像头返回的值了。&lt;/p&gt;&lt;p&gt;解决方案：&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; table-layout: fixed; width: 757px;"&gt;&lt;tbody style="word-wrap: break-word;"&gt;&lt;tr style="word-wrap: break-word;"&gt;&lt;td class="t_f" id="postmessage_546097" style="word-wrap: break-word; font-size: 14px;"&gt;&lt;p&gt;android:configChanges="orientation|keyboardHidden|navigation"&lt;br style="word-wrap: break-word;" /&gt;将这个属性添加到activity配置文件里面去吧，manifest.xml中&lt;/p&gt;&lt;p&gt;问题探究：&lt;/p&gt;&lt;p&gt;可能是两个原因造成的，一个就是上述的内存太小被迫释放造成的重新create窗体的方法。第二个可能性就是因为摄像头是横屏幕的应用，程序被动的切换到横屏状态，退出这个activtiy的时候就又被迫的切换回竖屏状态，造成横竖屏切换需要重新create这个activity。这样看来第二个问题的面大。&lt;/p&gt;&lt;p&gt;希望大家以后遇到android开发的问题多刨根问题，这个系统其实还是有些意思的。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/2148792.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2011/08/22/2148792.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2011/08/20/2147141.html</id><title type="text">UITableView 基本使用方法总结</title><summary type="text">1. 首先，Controller需要实现两个 delegate ，分别是 UITableViewDelegate 和 UITableViewDataSource 2.然后 UITableView对象的 delegate要设置为 self。 3. 然后就可以实现这些delegate的一些方法拉。 （1）- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView; 这个方法返回 tableview 有多少个sectionview plain//返回有多少个Sections-(NSInteger)numberOfSections.</summary><published>2011-08-20T06:24:00Z</published><updated>2011-08-20T06:24:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2011/08/20/2147141.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2011/08/20/2147141.html"/><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: mceinline;"&gt;&amp;nbsp; &amp;nbsp;1. &amp;nbsp; 首先，Controller需要实现两个 &amp;nbsp;delegate ，分别是 &amp;nbsp;&lt;/span&gt;UITableViewDelegate 和 &amp;nbsp;UITableViewDataSource&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; 2.然后 UITableView对象的 delegate要设置为 self。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; 3. 然后就可以实现这些delegate的一些方法拉。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; （1）- (&lt;span&gt;NSInteger&lt;/span&gt;)numberOfSectionsInTableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView; &amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 这个方法返回 tableview 有多少个section&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//返回有多少个Sections&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(NSInteger)numberOfSectionsInTableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;1;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; （2）- (&lt;span&gt;NSInteger&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)table numberOfRowsInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;这个方法返回 &amp;nbsp; 对应的section有多少个元素，也就是多少行。&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(NSInteger)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;numberOfRowsInSection:(NSInteger)section&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;10；&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; （3）- (&lt;span&gt;CGFloat&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView heightForRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;*)indexPath;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;这个方法返回指定的 row 的高度。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- (&lt;span&gt;CGFloat&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView heightForHeaderInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;这个方法返回指定的 section的header view 的高度。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- (&lt;span&gt;CGFloat&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView heightForFooterInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;这个方法返回指定的 section的footer view 的高度。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（4）- (&lt;span&gt;UITableViewCell&lt;/span&gt;&amp;nbsp;*)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView cellForRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;*)indexPath;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;返回指定的row 的cell。这个地方是比较关键的地方，一般在这个地方来定制各种个性化的 cell元素。这里只是使用最简单最基本&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;的cell 类型。其中有一个主标题 cell.textLabel 还有一个副标题cell.detailTextLabel, &amp;nbsp;还有一个 image在最前头 叫&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;cell.&lt;/span&gt;imageView. &amp;nbsp;还可以设置右边的图标，通过&lt;span&gt;cell.&lt;/span&gt;accessoryType&lt;span&gt;&amp;nbsp;可以设置是饱满的向右的蓝色箭头，还是单薄的向右箭头，&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;还是勾勾标记。 &amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(UITableViewCell&amp;nbsp;*)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;cellForRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;static&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;NSString&amp;nbsp;*&amp;nbsp;showUserInfoCellIdentifier&amp;nbsp;=&amp;nbsp;@&lt;/span&gt;&lt;span class="string" style="border-width: initial; border-color: initial; color: blue; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;"ShowUserInfoCell"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UITableViewCell&amp;nbsp;*&amp;nbsp;cell&amp;nbsp;=&amp;nbsp;[tableView_&amp;nbsp;dequeueReusableCellWithIdentifier:showUserInfoCellIdentifier];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(cell&amp;nbsp;==&amp;nbsp;nil)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//&amp;nbsp;Create&amp;nbsp;a&amp;nbsp;cell&amp;nbsp;to&amp;nbsp;display&amp;nbsp;an&amp;nbsp;ingredient.&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cell&amp;nbsp;=&amp;nbsp;[[[UITableViewCell&amp;nbsp;alloc]&amp;nbsp;initWithStyle:UITableViewCellStyleSubtitle&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reuseIdentifier:showUserInfoCellIdentifier]&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;autorelease];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//&amp;nbsp;Configure&amp;nbsp;the&amp;nbsp;cell.&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cell.textLabel.text=@&lt;span class="string" style="border-width: initial; border-color: initial; color: blue; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;"签名"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cell.detailTextLabel.text&amp;nbsp;=&amp;nbsp;[NSString&amp;nbsp;stringWithCString:userInfo.user_signature.c_str()&amp;nbsp;&amp;nbsp;encoding:NSUTF8StringEncoding];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; （5）- (&lt;span&gt;CGFloat&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView heightForHeaderInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 返回指定的 section 的header的高度&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(CGFloat)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;heightForHeaderInSection:(NSInteger)section&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(section&amp;nbsp;==0)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;80.0f;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;30.0f;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（6）- (&lt;span&gt;NSString&lt;/span&gt;&amp;nbsp;*)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView titleForHeaderInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 返回指定的section 的 header &amp;nbsp;的 title，如果这个section header &amp;nbsp;有返回view，那么title就不起作用了。&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(NSString&amp;nbsp;*)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;titleForHeaderInSection:(NSInteger)section&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(tableView&amp;nbsp;==&amp;nbsp;tableView_)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(section&amp;nbsp;==&amp;nbsp;0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;@&lt;/span&gt;&lt;span class="string" style="border-width: initial; border-color: initial; color: blue; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;"title&amp;nbsp;1"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(section&amp;nbsp;==&amp;nbsp;1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;@&lt;/span&gt;&lt;span class="string" style="border-width: initial; border-color: initial; color: blue; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;"title&amp;nbsp;2"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;nil;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;nil;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（7）&amp;nbsp;- (&lt;span&gt;UIView&lt;/span&gt;&amp;nbsp;*)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView viewForHeaderInSection:(&lt;span&gt;NSInteger&lt;/span&gt;)section&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;返回指定的 section header 的view，如果没有，这个函数可以不返回view&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(UIView&amp;nbsp;*)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;viewForHeaderInSection:(NSInteger)section&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(section&amp;nbsp;==&amp;nbsp;0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UIView*&amp;nbsp;header&amp;nbsp;=&amp;nbsp;[[[NSBundle&amp;nbsp;mainBundle]&amp;nbsp;loadNibNamed:&amp;nbsp;@&lt;span class="string" style="border-width: initial; border-color: initial; color: blue; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;"SettingHeaderView"&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;owner:&amp;nbsp;self&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options:&amp;nbsp;nil]&amp;nbsp;lastObject];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;nil;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(8) &amp;nbsp;- (&lt;span&gt;void&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView didSelectRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;&amp;nbsp;*)indexPath&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 当用户选中某个行的cell的时候，回调用这个。但是首先，必须设置tableview的一个属性为可以select 才行。&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;TableView.allowsSelection=YES;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;cell.selectionStyle=UITableViewCellSelectionStyleBlue;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 如果不希望响应select，那么就可以用下面的代码设置属性：&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;TableView.allowsSelection=NO; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;下面是响应select 点击函数，根据哪个section，哪个row 自己做出响应就好啦。&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(&lt;/span&gt;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;void&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;didSelectRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(indexPath.section&amp;nbsp;==&amp;nbsp;1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;if&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;(indexPath.section==0)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;switch&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;(indexPath.row)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//聊天&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;case&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;0:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[self&amp;nbsp;&amp;nbsp;onTalkToFriendBtn];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;break&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;default&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;:&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;break&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;else&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 如何让cell 能够响应 select，但是选中后的颜色又不发生改变呢，那么就设置&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;cell.&lt;/span&gt;&lt;span&gt;selectionStyle&lt;/span&gt;&lt;span&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;UITableViewCellSelectionStyleNone&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(UITableViewCell&amp;nbsp;*)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;cellForRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｛&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//cell被选中后的颜色不变&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cell.selectionStyle&amp;nbsp;=&amp;nbsp;UITableViewCellSelectionStyleNone;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｝&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（9）如何设置tableview &amp;nbsp;每行之间的 分割线&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 如果不需要分割线，那么就设置属性为&amp;nbsp;UITableViewCellSeparatorStyleNone &amp;nbsp;即可。&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（10）如何设置 tableview cell的背景颜色&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(UITableViewCell&amp;nbsp;*)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;cellForRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｛&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment" style="border-width: initial; border-color: initial; color: #008200; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;//设置背景颜色&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cell.contentView.backgroundColor=[UIColor&amp;nbsp;colorWithRed:0.957&amp;nbsp;green:0.957&amp;nbsp;blue:0.957&amp;nbsp;alpha:1];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｝ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; （11）&amp;nbsp;- (&lt;span&gt;void&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)&lt;span&gt;tableView&lt;/span&gt;&amp;nbsp;accessoryButtonTappedForRowWithIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;&amp;nbsp;*)indexPath&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 这个函数响应，用户点击cell 右边的 箭头（如果有的话）&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;（12）如何设置tableview 可以被编辑&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 首先要进入编辑模式：&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;[TableView&amp;nbsp;setEditing:YES&amp;nbsp;animated:YES]; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 如果要退出编辑模式，肯定就是设置为NO&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- (&lt;span&gt;UITableViewCellEditingStyle&lt;/span&gt;)tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)tableView editingStyleForRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;&amp;nbsp;*)indexPath&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;返回当前cell &amp;nbsp;要执行的是哪种编辑，下面的代码是 返回 删除 &amp;nbsp;模式&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-&amp;nbsp;(UITableViewCellEditingStyle)tableView:(UITableView&amp;nbsp;*)tableView&amp;nbsp;editingStyleForRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;return&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;UITableViewCellEditingStyleDelete;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-(&lt;span&gt;void&lt;/span&gt;) tableView:(&lt;span&gt;UITableView&lt;/span&gt;&amp;nbsp;*)aTableView&lt;/p&gt;&lt;p&gt;commitEditingStyle:(&lt;span&gt;UITableViewCellEditingStyle&lt;/span&gt;) editingStyle&lt;/p&gt;&lt;p&gt;forRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;&amp;nbsp;*)indexPath&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;通知告诉用户编辑了 哪个cell，对应上面的代码，我们在这个函数里面执行删除cell的操作。&lt;/p&gt;&lt;div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;"&gt;&lt;div class="bar" style="padding-left: 45px;"&gt;&lt;div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;"&gt;&lt;a href="http://blog.csdn.net/tangaowen/article/details/6438362" class="ViewSource" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url('http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-width: initial; border-color: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; border-style: none; padding: 1px;"&gt;view plain&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;ol start="1" class="dp-cpp" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; border-style: none; padding: 0px;"&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;-(&lt;/span&gt;&lt;span class="keyword" style="border-width: initial; border-color: initial; color: #006699; background-color: inherit; font-weight: bold; border-style: none; padding: 0px; margin: 0px;"&gt;void&lt;/span&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;)&amp;nbsp;tableView:(UITableView&amp;nbsp;*)aTableView&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;commitEditingStyle:(UITableViewCellEditingStyle)&amp;nbsp;editingStyle&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;forRowAtIndexPath:(NSIndexPath&amp;nbsp;*)indexPath&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｛&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[chatArray&amp;nbsp;&amp;nbsp;removeObjectAtIndex:indexPath.row];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; color: #5c5c5c; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[chatTableView&amp;nbsp;&amp;nbsp;reloadData];&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #6ce26c; background-color: #ffffff; color: inherit; line-height: 18px; margin: 0px !important;"&gt;&lt;span style="border-width: initial; border-color: initial; color: black; background-color: inherit; border-style: none; padding: 0px; margin: 0px;"&gt;｝ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; （13）如何获得 某一行的CELL对象&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;- (&lt;span&gt;UITableViewCell&lt;/span&gt;&amp;nbsp;*)cellForRowAtIndexPath:(&lt;span&gt;NSIndexPath&lt;/span&gt;&amp;nbsp;*)indexPath;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/2147141.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2011/08/20/2147141.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755265.html</id><title type="text">危险的两个函数GetCurrentDirectory和GetParent</title><summary type="text">最近这段时间用vc做了一个客户端程序，好长时间不做这种程序了，很是生疏，由于接手的别人的二手项目，大部分代码都已经完成了，只是跑起来问题很大，很多意料之中和意料之外的问题让人又爱又恨。其中遇到了两个函...</summary><published>2010-06-10T01:11:00Z</published><updated>2010-06-10T01:11:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755265.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755265.html"/><content type="html">&lt;p&gt;最近这段时间用vc做了一个客户端程序，好长时间不做这种程序了，很是生疏，由于接手的别人的二手项目，大部分代码都已经完成了，只是跑起来问题很大，很多意料之中和意料之外的问题让人又爱又恨。其中遇到了两个函数造成的奇怪问题，好好分析找到了原因，都是一些平时不注意，对一些函数错误的使用造成的。下面说说这两个函数。 &lt;p&gt;1、GetCurrentDirectoryDWORD WINAPI GetCurrentDirectory(&lt;br/&gt;  __in   DWORD nBufferLength,&lt;br/&gt;  __out  LPTSTR lpBuffer&lt;br/&gt;);&lt;br/&gt;&lt;p&gt;这个是函数原型，他是主要是作用是获取程序的当前目录，大部分指的是当前运行程序所在的运行目录。记得这个地方说的是大部分情况，不是所有，有些特殊的情况会返回时其他的路径。我们的程序在运行中需要有监护程序来引导，当我写完监护程序让他引导进入主程序的时候发现了奇怪的问题，程序整个界面打乱，一张图片都没有，去目录下查找图片存在，而且直接运行主程序没有这个问题。我们在主程序里面跟踪也没有头绪，每个函数都运行的正常的出奇，没有一点不妥的。可是就是在监护程序引导的情况下出现异常。经过判断感觉是路径发面出现问题，导致找不到图片。我们查看获取路径的函数，发现使用了GetCurrentDirectory，这个获取当前目录的函数按照常理应该没有问题，细想我们是在监护程序里面使用的shell把主程序调用起来的，应该是忘记了设置工作目录造成的吧，于是修改监护程序，设置工作目录，依旧无果，特殊调试发现这个函数获得的路径是监护程序的位置，看来这个GetCurrentDirectory函数本身应该是出了问题，我们使用的错误。后来查看了一些资料，微软也承认这个函数有时候不是那么恰当，他的这个获取的值收到很多的影响，所以如果只是为了获取当前程序运行路径，建议使用GetModuleFileName这个函数来处理，这个比较准，因为他获得是当前运行程序的存储路径。我们的程序也是使用这个之后恢复正常的。&lt;p&gt;2、GetParent&lt;p&gt;这个函数就本身使用来说是没有什么问题，只是我们有些时候在开发桌面应用程序的时候需要用的某个窗口置顶的问题，通常解决方法就那几个setforegroud之类的，可是这些问题都受制于如果你的父窗口不直前你也别想在最前面，所以通常会用SetParent(NULL)函数来搞掉父窗口。当搞掉父窗口之后GetParent函数也就废掉了，获取的值是NULL的。很多时候在vc里面操作父类的界面都需要拿到父类的句柄，然后再获取父类里面的某些控件的值，例如子窗口获取父类列表当前选中的值。当窗口不值钱，用GetParent一切ok，后来为了置前弄了SetParent(NULL)，编译无措，运行时候系统告诉你无效句柄，呵呵，这个问题好调出来，但是如果bug夺得焦头烂额的时候也是很难被发现的。对于这个的建议我们还是建议在基类里面默认设置一个包含父类句柄的变量，这样直接用就ok了。&lt;p&gt;上面的这些问题都是一些不良的编程习惯或者随意猜测函数弄出来的问题，总结上面的问题以后我再开始一个大型的c++项目之前一定要做好前期的设计，基础框架要做好，充分的用好几个好的设计模式，集中管理一些资源，界面等容易出现泄露问题的。等这个项目结束之后总结一些在大型C++项目里面基础框架必须包含的东西来分享一下。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755265.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755265.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755263.html</id><title type="text">ffmpeg文档8：软件缩放</title><summary type="text">指导8：软件缩放 软件缩放库libswscale 近来ffmpeg添加了新的接口：libswscale来处理图像缩放。 但是在前面我们使用img_convert来把RGB转换成YUV12，我们现在使用...</summary><published>2010-06-10T01:10:00Z</published><updated>2010-06-10T01:10:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755263.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755263.html"/><content type="html">&lt;p&gt;指导8：软件缩放 &lt;p&gt;软件缩放库libswscale &lt;p&gt;近来ffmpeg添加了新的接口：libswscale来处理图像缩放。 &lt;p&gt;但是在前面我们使用img_convert来把RGB转换成YUV12，我们现在使用新的接口。新接口更加标准和快速，而且我相信里面有了MMX优化代码。换句话说，它是做缩放更好的方式。 &lt;p&gt;我们将用来缩放的基本函数是sws_scale。但一开始，我们必需建立一个SwsContext的概念。这将让我们进行想要的转换，然后把它传递给 sws_scale函数。类似于在SQL中的预备阶段或者是在Python中编译的规则表达式regexp。要准备这个上下文，我们使用 sws_getContext函数，它需要我们源的宽度和高度，我们想要的宽度和高度，源的格式和想要转换成的格式，同时还有一些其它的参数和标志。然后我们像使用img_convert一样来使用sws_scale函数，唯一不同的是我们传递给的是SwsContext： &lt;p&gt;#include &amp;lt;ffmpeg/swscale.h&amp;gt; // include the header! &lt;p&gt;int queue_picture(VideoState *is, AVFrame *pFrame, double pts) { &lt;p&gt;static struct SwsContext *img_convert_ctx; &lt;p&gt;… &lt;p&gt;if(vp-&amp;gt;bmp) { &lt;p&gt;SDL_LockYUVOverlay(vp-&amp;gt;bmp); &lt;p&gt;dst_pix_fmt = PIX_FMT_YUV420P; &lt;p&gt;pict.data[0] = vp-&amp;gt;bmp-&amp;gt;pixels[0]; &lt;p&gt;pict.data[1] = vp-&amp;gt;bmp-&amp;gt;pixels[2]; &lt;p&gt;pict.data[2] = vp-&amp;gt;bmp-&amp;gt;pixels[1]; &lt;p&gt;pict.linesize[0] = vp-&amp;gt;bmp-&amp;gt;pitches[0]; &lt;p&gt;pict.linesize[1] = vp-&amp;gt;bmp-&amp;gt;pitches[2]; &lt;p&gt;pict.linesize[2] = vp-&amp;gt;bmp-&amp;gt;pitches[1]; &lt;p&gt;// Convert the image into YUV format that SDL uses &lt;p&gt;if(img_convert_ctx == NULL) { &lt;p&gt;int w = is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;width; &lt;p&gt;int h = is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height; &lt;p&gt;img_convert_ctx = sws_getContext(w, h, &lt;p&gt;is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;pix_fmt, &lt;p&gt;w, h, dst_pix_fmt, SWS_BICUBIC, &lt;p&gt;NULL, NULL, NULL); &lt;p&gt;if(img_convert_ctx == NULL) { &lt;p&gt;fprintf(stderr, “Cannot initialize the conversion context!\n”); &lt;p&gt;exit(1); &lt;p&gt;} &lt;p&gt;} &lt;p&gt;sws_scale(img_convert_ctx, pFrame-&amp;gt;data, &lt;p&gt;pFrame-&amp;gt;linesize, 0, &lt;p&gt;is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height, &lt;p&gt;pict.data, pict.linesize);  &lt;p&gt;我们把新的缩放器放到了合适的位置。希望这会让你知道libswscale能做什么。 &lt;p&gt;就这样，我们做完了！编译我们的播放器： &lt;p&gt;gcc -o tutorial08 tutorial08.c -lavutil -lavformat -lavcodec -lz -lm `sdl-config –cflags –libs`  &lt;p&gt;享受我们用C写的少于1000行的电影播放器吧。 &lt;p&gt;当然，还有很多事情要做。 &lt;p&gt;现在还要做什么？ &lt;p&gt;我们已经有了一个可以工作的播放器，但是它肯定还不够好。我们做了很多，但是还有很多要添加的性能： &lt;p&gt;·错误处理。我们代码中的错误处理是无穷的，多处理一些会更好。 &lt;p&gt;·暂停。我们不能暂停电影，这是一个很有用的功能。我们可以在大结构体中使用一个内部暂停变量，当用户暂停的时候就设置它。然后我们的音频，视频和解码线程检测到它后就不再输出任何东西。我们也使用av_read_play来支持网络。这很容易解释，但是你却不能明显的计算出，所以把这个作为一个家庭作业，如果你想尝试的话。提示，可以参考ffplay.c。 &lt;p&gt;·支持视频硬件特性。一个参考的例子，请参考Frame Grabbing在Martin的旧的指导中的相关部分。&lt;a href="http://www.inb.uni-luebeck.de/~boehme/libavcodec_update.html"&gt;http://www.inb.uni-luebeck.de/~boehme/libavcodec_update.html&lt;/a&gt; &lt;p&gt;·按字节跳转。如果你可以按照字节而不是秒的方式来计算出跳转位置，那么对于像VOB文件一样的有不连续时间戳的视频文件来说，定位会更加精确。 &lt;p&gt;·丢弃帧。如果视频落后的太多，我们应当把下一帧丢弃掉而不是设置一个短的刷新时间。 &lt;p&gt;·支持网络。现在的电影播放器还不能播放网络流媒体。 &lt;p&gt;·支持像YUV文件一样的原始视频流。如果我们的播放器支持的话，因为我们不能猜测出时基和大小，我们应该加入一些参数来进行相应的设置。 &lt;p&gt;·全屏。 &lt;p&gt;·多种参数，例如：不同图像格式；参考ffplay.c中的命令开关。 &lt;p&gt;·其它事情，例如：在结构体中的音频缓冲区应该对齐。 &lt;p&gt;如果你想了解关于ffmpeg更多的事情，我们已经包含了其中的一部分。下一步应该学习的就是如何来编码多媒体。一个好的入手点是在ffmpeg中的output_example.c文件。我可以为它写另外一个指导，但是我没有足够的时间来做。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755263.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755263.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755261.html</id><title type="text">ffmpeg文档6：同步音频</title><summary type="text">指导6：同步音频 同步音频 现在我们已经有了一个比较像样的播放器。所以让我们看一下还有哪些零碎的东西没处理。上次，我们掩饰了一点同步问题，也就是同步音频到视频而不是其它的同步方式。我们将采用和视频一样...</summary><published>2010-06-10T01:09:00Z</published><updated>2010-06-10T01:09:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755261.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755261.html"/><content type="html">&lt;p&gt;指导6：同步音频 &lt;p&gt;同步音频 &lt;p&gt;现在我们已经有了一个比较像样的播放器。所以让我们看一下还有哪些零碎的东西没处理。上次，我们掩饰了一点同步问题，也就是同步音频到视频而不是其它的同步方式。我们将采用和视频一样的方式：做一个内部视频时钟来记录视频线程播放了多久，然后同步音频到上面去。后面我们也来看一下如何推而广之把音频和视频都同步到外部时钟。 &lt;p&gt;生成一个视频时钟 &lt;p&gt;现在我们要生成一个类似于上次我们的声音时钟的视频时钟：一个给出当前视频播放时间的内部值。开始，你可能会想这和使用上一帧的时间戳来更新定时器一样简单。但是，不要忘了视频帧之间的时间间隔是很长的，以毫秒为计量的。解决办法是跟踪另外一个值：我们在设置上一帧时间戳的时候的时间值。于是当前视频时间值就是PTS_of_last_frame + (current_time – time_elapsed_since_PTS_value_was_set)。这种解决方式与我们在函数get_audio_clock中的方式很类似。 &lt;p&gt;所在在我们的大结构体中，我们将放上一个双精度浮点变量video_current_pts和一个64位宽整型变量video_current_pts_time。时钟更新将被放在video_refresh_timer函数中。 &lt;p&gt;void video_refresh_timer(void *userdata) { &lt;p&gt;if(is-&amp;gt;video_st) { &lt;p&gt;if(is-&amp;gt;pictq_size == 0) { &lt;p&gt;schedule_refresh(is, 1); &lt;p&gt;} else { &lt;p&gt;vp = &amp;amp;is-&amp;gt;pictq[is-&amp;gt;pictq_rindex]; &lt;p&gt;is-&amp;gt;video_current_pts = vp-&amp;gt;pts; &lt;p&gt;is-&amp;gt;video_current_pts_time = av_gettime();  &lt;p&gt;不要忘记在stream_component_open函数中初始化它： &lt;p&gt;is-&amp;gt;video_current_pts_time = av_gettime();  &lt;p&gt;现在我们需要一种得到信息的方式： &lt;p&gt;double get_video_clock(VideoState *is) { &lt;p&gt;double delta; &lt;p&gt;delta = (av_gettime() – is-&amp;gt;video_current_pts_time) / 1000000.0; &lt;p&gt;return is-&amp;gt;video_current_pts + delta; &lt;p&gt;}  &lt;p&gt;提取时钟 &lt;p&gt;但是为什么要强制使用视频时钟呢？我们更改视频同步代码以致于音频和视频不会试着去相互同步。想像一下我们让它像ffplay一样有一个命令行参数。所以让我们抽象一样这件事情：我们将做一个新的封装函数get_master_clock，用来检测av_sync_type变量然后决定调用 get_audio_clock还是get_video_clock或者其它的想使用的获得时钟的函数。我们甚至可以使用电脑时钟，这个函数我们叫做 get_external_clock： &lt;p&gt;enum { &lt;p&gt;AV_SYNC_AUDIO_MASTER, &lt;p&gt;AV_SYNC_VIDEO_MASTER, &lt;p&gt;AV_SYNC_EXTERNAL_MASTER, &lt;p&gt;}; &lt;p&gt;#define DEFAULT_AV_SYNC_TYPE AV_SYNC_VIDEO_MASTER &lt;p&gt;double get_master_clock(VideoState *is) { &lt;p&gt;if(is-&amp;gt;av_sync_type == AV_SYNC_VIDEO_MASTER) { &lt;p&gt;return get_video_clock(is); &lt;p&gt;} else if(is-&amp;gt;av_sync_type == AV_SYNC_AUDIO_MASTER) { &lt;p&gt;return get_audio_clock(is); &lt;p&gt;} else { &lt;p&gt;return get_external_clock(is); &lt;p&gt;} &lt;p&gt;} &lt;p&gt;main() { &lt;p&gt;… &lt;p&gt;is-&amp;gt;av_sync_type = DEFAULT_AV_SYNC_TYPE; &lt;p&gt;… &lt;p&gt;}  &lt;p&gt;同步音频 &lt;p&gt;现在是最难的部分：同步音频到视频时钟。我们的策略是测量声音的位置，把它与视频时间比较然后算出我们需要修正多少的样本数，也就是说：我们是否需要通过丢弃样本的方式来加速播放还是需要通过插值样本的方式来放慢播放？ &lt;p&gt;我们将在每次处理声音样本的时候运行一个synchronize_audio的函数来正确的收缩或者扩展声音样本。然而，我们不想在每次发现有偏差的时候都进行同步，因为这样会使同步音频多于视频包。所以我们为函数synchronize_audio设置一个最小连续值来限定需要同步的时刻，这样我们就不会总是在调整了。当然，就像上次那样，”失去同步”意味着声音时钟和视频时钟的差异大于我们的阈值。 &lt;p&gt;所以我们将使用一个分数系数，叫c，所以现在可以说我们得到了N个失去同步的声音样本。失去同步的数量可能会有很多变化，所以我们要计算一下失去同步的长度的均值。例如，第一次调用的时候，显示出来我们失去同步的长度为40ms，下次变为50ms等等。但是我们不会使用一个简单的均值，因为距离现在最近的值比靠前的值要重要的多。所以我们将使用一个分数系统，叫c，然后用这样的公式来计算差异：diff_sum = new_diff + diff_sum*c。当我们准备好去找平均差异的时候，我们用简单的计算方式：avg_diff = diff_sum * (1-c)。 &lt;p&gt;注意：为什么会在这里？这个公式看来很神奇！嗯，它基本上是一个使用等比级数的加权平均值。我不知道这是否有名字（我甚至查过维基百科！），但是如果想要更多的信息，这里是一个解释&lt;a href="http://www.dranger.com/ffmpeg/weightedmean.html"&gt;http://www.dranger.com/ffmpeg/weightedmean.html&lt;/a&gt;或者在&lt;a href="http://www.dranger.com/ffmpeg/weightedmean.txt"&gt;http://www.dranger.com/ffmpeg/weightedmean.txt&lt;/a&gt;里。  &lt;p&gt;下面是我们的函数： &lt;p&gt;int synchronize_audio(VideoState *is, short *samples, &lt;p&gt;int samples_size, double pts) { &lt;p&gt;int n; &lt;p&gt;double ref_clock; &lt;p&gt;n = 2 * is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;channels; &lt;p&gt;if(is-&amp;gt;av_sync_type != AV_SYNC_AUDIO_MASTER) { &lt;p&gt;double diff, avg_diff; &lt;p&gt;int wanted_size, min_size, max_size, nb_samples; &lt;p&gt;ref_clock = get_master_clock(is); &lt;p&gt;diff = get_audio_clock(is) – ref_clock; &lt;p&gt;if(diff &amp;lt; AV_NOSYNC_THRESHOLD) { &lt;p&gt;// accumulate the diffs &lt;p&gt;is-&amp;gt;audio_diff_cum = diff + is-&amp;gt;audio_diff_avg_coef &lt;p&gt;* is-&amp;gt;audio_diff_cum; &lt;p&gt;if(is-&amp;gt;audio_diff_avg_count &amp;lt; AUDIO_DIFF_AVG_NB) { &lt;p&gt;is-&amp;gt;audio_diff_avg_count++; &lt;p&gt;} else { &lt;p&gt;avg_diff = is-&amp;gt;audio_diff_cum * (1.0 – is-&amp;gt;audio_diff_avg_coef); &lt;p&gt;} &lt;p&gt;} else { &lt;p&gt;is-&amp;gt;audio_diff_avg_count = 0; &lt;p&gt;is-&amp;gt;audio_diff_cum = 0; &lt;p&gt;} &lt;p&gt;} &lt;p&gt;return samples_size; &lt;p&gt;}  &lt;p&gt;现在我们已经做得很好；我们已经近似的知道如何用视频或者其它的时钟来调整音频了。所以让我们来计算一下要在添加和砍掉多少样本，并且如何在”Shrinking/expanding buffer code”部分来写上代码： &lt;p&gt;if(fabs(avg_diff) &amp;gt;= is-&amp;gt;audio_diff_threshold) { &lt;p&gt;wanted_size = samples_size + &lt;p&gt;((int)(diff * is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;sample_rate) * n); &lt;p&gt;min_size = samples_size * ((100 – SAMPLE_CORRECTION_PERCENT_MAX) &lt;p&gt;/ 100); &lt;p&gt;max_size = samples_size * ((100 + SAMPLE_CORRECTION_PERCENT_MAX) &lt;p&gt;/ 100); &lt;p&gt;if(wanted_size &amp;lt; min_size) { &lt;p&gt;wanted_size = min_size; &lt;p&gt;} else if (wanted_size &amp;gt; max_size) { &lt;p&gt;wanted_size = max_size; &lt;p&gt;}  &lt;p&gt;记住audio_length * (sample_rate * # of channels * 2)就是audio_length秒时间的声音的样本数。所以，我们想要的样本数就是我们根据声音偏移添加或者减少后的声音样本数。我们也可以设置一个范围来限定我们一次进行修正的长度，因为如果我们改变的太多，用户会听到刺耳的声音。 &lt;p&gt;修正样本数 &lt;p&gt;现在我们要真正的修正一下声音。你可能会注意到我们的同步函数synchronize_audio返回了一个样本数，这可以告诉我们有多少个字节被送到流中。所以我们只要调整样本数为wanted_size就可以了。这会让样本更小一些。但是如果我们想让它变大，我们不能只是让样本大小变大，因为在缓冲区中没有多余的数据！所以我们必需添加上去。但是我们怎样来添加呢？最笨的办法就是试着来推算声音，所以让我们用已有的数据在缓冲的末尾添加上最后的样本。 &lt;p&gt;if(wanted_size &amp;lt; samples_size) { &lt;p&gt;samples_size = wanted_size; &lt;p&gt;} else if(wanted_size &amp;gt; samples_size) { &lt;p&gt;uint8_t *samples_end, *q; &lt;p&gt;int nb; &lt;p&gt;nb = (samples_size – wanted_size); &lt;p&gt;samples_end = (uint8_t *)samples + samples_size – n; &lt;p&gt;q = samples_end + n; &lt;p&gt;while(nb &amp;gt; 0) { &lt;p&gt;memcpy(q, samples_end, n); &lt;p&gt;q += n; &lt;p&gt;nb -= n; &lt;p&gt;} &lt;p&gt;samples_size = wanted_size; &lt;p&gt;}  &lt;p&gt;现在我们通过这个函数返回的是样本数。我们现在要做的是使用它： &lt;p&gt;void audio_callback(void *userdata, Uint8 *stream, int len) { &lt;p&gt;VideoState *is = (VideoState *)userdata; &lt;p&gt;int len1, audio_size; &lt;p&gt;double pts; &lt;p&gt;while(len &amp;gt; 0) { &lt;p&gt;if(is-&amp;gt;audio_buf_index &amp;gt;= is-&amp;gt;audio_buf_size) { &lt;p&gt;audio_size = audio_decode_frame(is, is-&amp;gt;audio_buf, sizeof(is-&amp;gt;audio_buf), &amp;amp;pts); &lt;p&gt;if(audio_size &amp;lt; 0) { &lt;p&gt;is-&amp;gt;audio_buf_size = 1024; &lt;p&gt;memset(is-&amp;gt;audio_buf, 0, is-&amp;gt;audio_buf_size); &lt;p&gt;} else { &lt;p&gt;audio_size = synchronize_audio(is, (int16_t *)is-&amp;gt;audio_buf, &lt;p&gt;audio_size, pts); &lt;p&gt;is-&amp;gt;audio_buf_size = audio_size;  &lt;p&gt;我们要做的是把函数synchronize_audio插入进去。（同时，保证在初始化上面变量的时候检查一下代码，这些我没有赘述）。 &lt;p&gt;结束之前的最后一件事情：我们需要添加一个if语句来保证我们不会在视频为主时钟的时候也来同步视频。 &lt;p&gt;if(is-&amp;gt;av_sync_type != AV_SYNC_VIDEO_MASTER) { &lt;p&gt;ref_clock = get_master_clock(is); &lt;p&gt;diff = vp-&amp;gt;pts – ref_clock; &lt;p&gt;sync_threshold = (delay &amp;gt; AV_SYNC_THRESHOLD) ? delay : &lt;p&gt;AV_SYNC_THRESHOLD; &lt;p&gt;if(fabs(diff) &amp;lt; AV_NOSYNC_THRESHOLD) { &lt;p&gt;if(diff &amp;lt;= -sync_threshold) { &lt;p&gt;delay = 0; &lt;p&gt;} else if(diff &amp;gt;= sync_threshold) { &lt;p&gt;delay = 2 * delay; &lt;p&gt;} &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;添加后就可以了。要保证整个程序中我没有赘述的变量都被初始化过了。然后编译它： &lt;p&gt;gcc -o tutorial06 tutorial06.c -lavutil -lavformat -lavcodec -lz -lm`sdl-config –cflags –libs`  &lt;p&gt;然后你就可以运行它了。 &lt;p&gt;下次我们要做的是让你可以让电影快退和快进。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755261.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755261.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755262.html</id><title type="text">ffmpeg文档7：快进快退</title><summary type="text">指导7：快进快退 处理快进快退命令 现在我们来为我们的播放器加入一些快进和快退的功能，因为如果你不能全局搜索一部电影是很让人讨厌的。同时，这将告诉你av_seek_frame函数是多么容易使用。 我们...</summary><published>2010-06-10T01:09:00Z</published><updated>2010-06-10T01:09:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755262.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755262.html"/><content type="html">&lt;p&gt;指导7：快进快退 &lt;p&gt;处理快进快退命令 &lt;p&gt;现在我们来为我们的播放器加入一些快进和快退的功能，因为如果你不能全局搜索一部电影是很让人讨厌的。同时，这将告诉你av_seek_frame函数是多么容易使用。 &lt;p&gt;我们将在电影播放中使用左方向键和右方向键来表示向后和向前一小段，使用向上和向下键来表示向前和向后一大段。这里一小段是10秒，一大段是60秒。所以我们需要设置我们的主循环来捕捉键盘事件。然而当我们捕捉到键盘事件后我们不能直接调用av_seek_frame函数。我们要主要的解码线程 decode_thread的循环中做这些。所以，我们要添加一些变量到大结构体中，用来包含新的跳转位置和一些跳转标志： &lt;p&gt;int seek_req; &lt;p&gt;int seek_flags; &lt;p&gt;int64_t seek_pos;  &lt;p&gt;现在让我们在主循环中捕捉按键： &lt;p&gt;for(;;) { &lt;p&gt;double incr, pos; &lt;p&gt;SDL_WaitEvent(&amp;amp;event); &lt;p&gt;switch(event.type) { &lt;p&gt;case SDL_KEYDOWN: &lt;p&gt;switch(event.key.keysym.sym) { &lt;p&gt;case SDLK_LEFT: &lt;p&gt;incr = -10.0; &lt;p&gt;goto do_seek; &lt;p&gt;case SDLK_RIGHT: &lt;p&gt;incr = 10.0; &lt;p&gt;goto do_seek; &lt;p&gt;case SDLK_UP: &lt;p&gt;incr = 60.0; &lt;p&gt;goto do_seek; &lt;p&gt;case SDLK_DOWN: &lt;p&gt;incr = -60.0; &lt;p&gt;goto do_seek; &lt;p&gt;do_seek: &lt;p&gt;if(global_video_state) { &lt;p&gt;pos = get_master_clock(global_video_state); &lt;p&gt;pos += incr; &lt;p&gt;stream_seek(global_video_state, &lt;p&gt;(int64_t)(pos * AV_TIME_BASE), incr); &lt;p&gt;} &lt;p&gt;break; &lt;p&gt;default: &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;break;  &lt;p&gt;为了检测按键，我们先查了一下是否有SDL_KEYDOWN事件。然后我们使用event.key.keysym.sym来判断哪个按键被按下。一旦我们知道了如何来跳转，我们就来计算新的时间，方法为把增加的时间值加到从函数get_master_clock中得到的时间值上。然后我们调用 stream_seek函数来设置seek_pos等变量。我们把新的时间转换成为avcodec中的内部时间戳单位。在流中调用那个时间戳将使用帧而不是用秒来计算，公式为seconds = frames * time_base(fps)。默认的avcodec值为1,000,000fps（所以2秒的内部时间戳为2,000,000）。在后面我们来看一下为什么要把这个值进行一下转换。 &lt;p&gt;这就是我们的stream_seek函数。请注意我们设置了一个标志为后退服务： &lt;p&gt;void stream_seek(VideoState *is, int64_t pos, int rel) { &lt;p&gt;if(!is-&amp;gt;seek_req) { &lt;p&gt;is-&amp;gt;seek_pos = pos; &lt;p&gt;is-&amp;gt;seek_flags = rel &amp;lt; 0 ? AVSEEK_FLAG_BACKWARD : 0; &lt;p&gt;is-&amp;gt;seek_req = 1; &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;现在让我们看一下如果在decode_thread中实现跳转。你会注意到我们已经在源文件中标记了一个叫做”seek stuff goes here”的部分。现在我们将把代码写在这里。 &lt;p&gt;跳转是围绕着av_seek_frame函数的。这个函数用到了一个格式上下文，一个流，一个时间戳和一组标记来作为它的参数。这个函数将会跳转到你所给的时间戳的位置。时间戳的单位是你传递给函数的流的时基time_base。然而，你并不是必需要传给它一个流（流可以用-1来代替）。如果你这样做了，时基time_base将会是avcodec中的内部时间戳单位，或者是1000000fps。这就是为什么我们在设置seek_pos的时候会把位置乘以AV_TIME_BASER的原因。 &lt;p&gt;但是，如果给av_seek_frame函数的stream参数传递传-1,你有时会在播放某些文件的时候遇到问题（比较少见），所以我们会取文件中的第一个流并且把它传递到av_seek_frame函数。不要忘记我们也要把时间戳timestamp的单位进行转化。 &lt;p&gt;if(is-&amp;gt;seek_req) { &lt;p&gt;int stream_index= -1; &lt;p&gt;int64_t seek_target = is-&amp;gt;seek_pos; &lt;p&gt;if (is-&amp;gt;videoStream &amp;gt;= 0) stream_index = is-&amp;gt;videoStream; &lt;p&gt;else if(is-&amp;gt;audioStream &amp;gt;= 0) stream_index = is-&amp;gt;audioStream; &lt;p&gt;if(stream_index&amp;gt;=0){ &lt;p&gt;seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, &lt;p&gt;pFormatCtx-&amp;gt;streams[stream_index]-&amp;gt;time_base); &lt;p&gt;} &lt;p&gt;if(av_seek_frame(is-&amp;gt;pFormatCtx, stream_index, &lt;p&gt;seek_target, is-&amp;gt;seek_flags) &amp;lt; 0) { &lt;p&gt;fprintf(stderr, “%s: error while seeking\n”, &lt;p&gt;is-&amp;gt;pFormatCtx-&amp;gt;filename); &lt;p&gt;} else {  &lt;p&gt;这里av_rescale_q(a,b,c)是用来把时间戳从一个时基调整到另外一个时基时候用的函数。它基本的动作是计算a*b/c，但是这个函数还是必需的，因为直接计算会有溢出的情况发生。AV_TIME_BASE_Q是AV_TIME_BASE作为分母后的版本。它们是很不相同的：AV_TIME_BASE * time_in_seconds = avcodec_timestamp而AV_TIME_BASE_Q * avcodec_timestamp = time_in_seconds（注意AV_TIME_BASE_Q实际上是一个AVRational对象，所以你必需使用avcodec中特定的q函数来处理它）。 &lt;p&gt;清空我们的缓冲 &lt;p&gt;我们已经正确设定了跳转位置，但是我们还没有结束。记住我们有一个堆放了很多包的队列。既然我们跳到了不同的位置，我们必需把队列中的内容清空否则电影是不会跳转的。不仅如此，avcodec也有它自己的内部缓冲，也需要每次被清空。 &lt;p&gt;要实现这个，我们需要首先写一个函数来清空我们的包队列。然后我们需要一种命令声音和视频线程来清空avcodec内部缓冲的办法。我们可以在清空队列后把特定的包放入到队列中，然后当它们检测到特定的包的时候，它们就会把自己的内部缓冲清空。 &lt;p&gt;让我们开始写清空函数。其实很简单的，所以我直接把代码写在下面： &lt;p&gt;static void packet_queue_flush(PacketQueue *q) { &lt;p&gt;AVPacketList *pkt, *pkt1; &lt;p&gt;SDL_LockMutex(q-&amp;gt;mutex); &lt;p&gt;for(pkt = q-&amp;gt;first_pkt; pkt != NULL; pkt = pkt1) { &lt;p&gt;pkt1 = pkt-&amp;gt;next; &lt;p&gt;av_free_packet(&amp;amp;pkt-&amp;gt;pkt); &lt;p&gt;av_freep(&amp;amp;pkt); &lt;p&gt;} &lt;p&gt;q-&amp;gt;last_pkt = NULL; &lt;p&gt;q-&amp;gt;first_pkt = NULL; &lt;p&gt;q-&amp;gt;nb_packets = 0; &lt;p&gt;q-&amp;gt;size = 0; &lt;p&gt;SDL_UnlockMutex(q-&amp;gt;mutex); &lt;p&gt;}  &lt;p&gt;既然队列已经清空了，我们放入”清空包”。但是开始我们要定义和创建这个包： &lt;p&gt;AVPacket flush_pkt; &lt;p&gt;main() { &lt;p&gt;… &lt;p&gt;av_init_packet(&amp;amp;flush_pkt); &lt;p&gt;flush_pkt.data = “FLUSH”; &lt;p&gt;… &lt;p&gt;}  &lt;p&gt;现在我们把这个包放到队列中： &lt;p&gt;} else { &lt;p&gt;if(is-&amp;gt;audioStream &amp;gt;= 0) { &lt;p&gt;packet_queue_flush(&amp;amp;is-&amp;gt;audioq); &lt;p&gt;packet_queue_put(&amp;amp;is-&amp;gt;audioq, &amp;amp;flush_pkt); &lt;p&gt;} &lt;p&gt;if(is-&amp;gt;videoStream &amp;gt;= 0) { &lt;p&gt;packet_queue_flush(&amp;amp;is-&amp;gt;videoq); &lt;p&gt;packet_queue_put(&amp;amp;is-&amp;gt;videoq, &amp;amp;flush_pkt); &lt;p&gt;} &lt;p&gt;} &lt;p&gt;is-&amp;gt;seek_req = 0; &lt;p&gt;}  &lt;p&gt;（这些代码片段是接着前面decode_thread中的代码片段的）我们也需要修改packet_queue_put函数才不至于直接简单复制了这个包： &lt;p&gt;int packet_queue_put(PacketQueue *q, AVPacket *pkt) { &lt;p&gt;AVPacketList *pkt1; &lt;p&gt;if(pkt != &amp;amp;flush_pkt &amp;amp;&amp;amp; av_dup_packet(pkt) &amp;lt; 0) { &lt;p&gt;return -1; &lt;p&gt;}  &lt;p&gt;然后在声音线程和视频线程中，我们在packet_queue_get后立即调用函数avcodec_flush_buffers： &lt;p&gt;if(packet_queue_get(&amp;amp;is-&amp;gt;audioq, pkt, 1) &amp;lt; 0) { &lt;p&gt;return -1; &lt;p&gt;} &lt;p&gt;if(packet-&amp;gt;data == flush_pkt.data) { &lt;p&gt;avcodec_flush_buffers(is-&amp;gt;audio_st-&amp;gt;codec); &lt;p&gt;continue; &lt;p&gt;}  &lt;p&gt;上面的代码片段与视频线程中的一样，只要把”audio”换成”video”。 &lt;p&gt;就这样，让我们编译我们的播放器： &lt;p&gt;gcc -o tutorial07 tutorial07.c -lavutil -lavformat -lavcodec -lz -lm`sdl-config –cflags –libs`  &lt;p&gt;试一下！我们几乎已经都做完了；下次我们只要做一点小的改动就好了，那就是检测ffmpeg提供的小的软件缩放采样。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755262.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755262.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755257.html</id><title type="text">ffmpeg文档4:创建线程</title><summary type="text">综述前面我们利用SDL的音频函数实现了对音频解码和播放的支持，我们定义一个包含音频回调函数callbacks的线程函数，当我们需要音频的时候就使SDL启动这个线程。现在我们将要对视频播放做同样的事情，...</summary><published>2010-06-10T01:08:00Z</published><updated>2010-06-10T01:08:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755257.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755257.html"/><content type="html">&lt;p&gt;&lt;strong&gt;综述&lt;/strong&gt;&lt;br&gt;前面我们利用SDL的音频函数实现了对音频解码和播放的支持，我们定义一个包含音频回调函数callbacks的线程函数，当我们需要音频的时候就使SDL启动这个线程。现在我们将要对视频播放做同样的事情，这样能使代码更容易模块化和协作，尤其有利于音视频同步，那么我们从哪里开始呢？ &lt;br&gt;首先注意到，我们的主函数需要做太多的事情：运行event循环，读packet，解码视频，我们需要做的就 &lt;br&gt;是把各个部分分开，创建一个线程负责解码出packets，并把音频、视频的packet放到各自的队列中，并 &lt;br&gt;由相应的音频、视频处理线程读取，我们已经创建了所需要的音频线程，视频处理线程会有点复杂，因为 &lt;br&gt;我们需要自己来播放视频数据（音频由SDL来播放）。我们会在主循环中添加我们的播放代码，但是我们 &lt;br&gt;要把视频播放与事件驱动循环结合起来，而不是仅仅在主循环中播放，这就意味着我们先对视频解码，把 &lt;br&gt;解码生成的视频帧放在另外一个队列中，然后创建一个常规事件(FF_REFRESH_EVENT)并加到事件驱动系统，每当事件驱动循环遇到这个事件(FF_REFRESH_EVENT)就播放下一帧，下面是上述功能的一个手绘的字符图示 &lt;br&gt;________ audio _______ _____ &lt;br&gt;| | pkts | | | | to spkr &lt;br&gt;| DECODE |—–&amp;gt;| AUDIO |—&amp;gt;| SDL |–&amp;gt; &lt;br&gt;|________| |_______| |_____| &lt;br&gt;| video _______ &lt;br&gt;| pkts | | &lt;br&gt;+———-&amp;gt;| VIDEO | &lt;br&gt;________ |_______| _______ &lt;br&gt;| | | | | &lt;br&gt;| EVENT | +——&amp;gt;| VIDEO | to mon. &lt;br&gt;| LOOP |—————–&amp;gt;| DISP. |–&amp;gt; &lt;br&gt;|_______|&amp;lt;—FF_REFRESH—-|_______| &lt;p&gt;使用SDL的SDL_Delay线程，能够精确控制下一个视频帧的播放时间，这就是我们把对视频播放的控制与事件驱动循环结合起来的主要原因，当我们在下一章最终讲音视频同步时，对于在正确的时间刷新正确的图片，添加这部分代码将不再是难事。 &lt;br&gt;&lt;strong&gt;简化代码&lt;/strong&gt;&lt;br&gt;我们需要对代码做一些修剪，我们拥有所有音频和视频编解码信息，还需要添加队列和buffer和其他一些 &lt;br&gt;东西，所有这些东西都为一个逻辑单元服务–电影，所以我们应该创建一个大的结构体把所有这些信息 &lt;br&gt;都包括进去，命名为VideoState &lt;br&gt;typedef struct VideoState { &lt;p&gt;AVFormatContext *pFormatCtx; &lt;br&gt;int videoStream, audioStream; &lt;br&gt;AVStream *audio_st; &lt;br&gt;PacketQueue audioq; &lt;br&gt;uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; &lt;br&gt;unsigned int audio_buf_size; &lt;br&gt;unsigned int audio_buf_index; &lt;br&gt;AVPacket audio_pkt; &lt;br&gt;uint8_t *audio_pkt_data; &lt;br&gt;int audio_pkt_size; &lt;br&gt;AVStream *video_st; &lt;br&gt;PacketQueue videoq; &lt;p&gt;VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; &lt;br&gt;int pictq_size, pictq_rindex, pictq_windex; &lt;br&gt;SDL_mutex *pictq_mutex; &lt;br&gt;SDL_cond *pictq_cond; &lt;br&gt;SDL_Thread *parse_tid; &lt;br&gt;SDL_Thread *video_tid; &lt;p&gt;char filename[1024]; &lt;br&gt;int quit; &lt;br&gt;} VideoState; &lt;br&gt;我们先大致看一下这一个结构体：基本信息AVFormatContext *pFormatCtx;音视频流指数及其相应的AVStream实体，把与音频有关的audio_buffer、audio_buffer_size等这些buffer也放到这个结构体中，为视频也创建一个队列和buffer（用来存放解码后的视频帧，而不需要一个真正的队列来存放）， &lt;br&gt;VideoPicture struct 是我们自己创建的结构体，当用到时会对它进行分析，为我们创建的两个线程分别 &lt;br&gt;分配指针，quit标志，还有电影文件名。现在我们回到主函数中看看这些能使程序发生哪些变化，首先初始化VideoState struct： &lt;br&gt;int main(int argc, char *argv[]) { &lt;br&gt;SDL_Event event; &lt;p&gt;VideoState *is; &lt;p&gt;is = av_mallocz(sizeof(VideoState)); &lt;br&gt;av_mallocz()是一个很好的函数，它为我们分配内存并将其内容清零。 &lt;br&gt;然后初始化display buffer (pictq)的互斥锁，因为事件驱动循环要调用播放函数，从display buffer &lt;br&gt;(pictq)中取出已解码的数据帧，同时视频解码函数要将其生成的数据帧放入display buffer (pictq)， &lt;br&gt;两者就会产生冲突，这是一个典型的竞争情况，我们要在启动任一线程之前定义为其分配互斥锁，另外把 &lt;br&gt;电影名拷贝到VideoState。 &lt;br&gt;pstrcpy(is-&amp;gt;filename, sizeof(is-&amp;gt;filename), argv[1]); &lt;p&gt;is-&amp;gt;pictq_mutex = SDL_CreateMutex(); &lt;br&gt;is-&amp;gt;pictq_cond = SDL_CreateCond(); &lt;br&gt;pstrcpy()是FFmpeg中的函数，和strncpy相比，它提供额外的边界检查。 &lt;br&gt;&lt;strong&gt;第一个线程 &lt;br&gt;&lt;/strong&gt;现在我们终于可以创建线程，并可以做一些实际的工作。 &lt;br&gt;schedule_refresh(is, 40); &lt;p&gt;is-&amp;gt;parse_tid = SDL_CreateThread(decode_thread, is); &lt;br&gt;if(!is-&amp;gt;parse_tid) { &lt;br&gt;av_free(is); &lt;br&gt;return -1; &lt;br&gt;} &lt;br&gt;schedule_refresh()函数将在稍后定义，它完成的功能是每隔一定数目的毫秒数向系统发送一个 &lt;br&gt;FF_REFRESH_EVENT 事件驱动，从而调用事件驱动循环中的视频刷新函数，现在先来看一下 &lt;br&gt;SDL_CreatThread()函数，它创建一个线程运行在给定的函数，并能向此函数传递用户定义数据，此线程对所在进程的内存区域具有完全的访问权，我们就用这种方式调用decode_thread()和传递VideoState，这个函数的前半部分没有什么新鲜的东西，只是打开文件，找到音频、视频流，唯一不同的地方是要把format_context保存到VideoState中，再找到音频、视频流位置后，就调用另外一个我们将要定义的函数stream_component_open()使用这种方法将程序分开非常自然，由于对音视频的解码初始化功能相似，将其放到一个函数中能节省很多代码。 &lt;br&gt;在stream_component_open()函数中，我们找到codec、decoder初始化音频选项、保存重要信息到 &lt;br&gt;VideoState中，启动音频、视频、线程，我们也可以在此添加选项，使其能够指定编解码器而不是自动探测，等等，下面是函数的内容： &lt;br&gt;int stream_component_open(VideoState *is, int stream_index) { &lt;br&gt;AVFormatContext *pFormatCtx = is-&amp;gt;pFormatCtx; &lt;br&gt;AVCodecContext *codecCtx; &lt;br&gt;AVCodec *codec; &lt;br&gt;SDL_AudioSpec wanted_spec, spec; &lt;p&gt;if(stream_index &amp;lt; 0 || stream_index &amp;gt;= pFormatCtx-&amp;gt;nb_streams) { &lt;br&gt;return -1; &lt;br&gt;} &lt;p&gt;// Get a pointer to the codec context for the video stream &lt;br&gt;codecCtx = pFormatCtx-&amp;gt;streams[stream_index]-&amp;gt;codec; &lt;p&gt;if(codecCtx-&amp;gt;codec_type == CODEC_TYPE_AUDIO) { &lt;br&gt;// Set audio settings from codec info &lt;br&gt;wanted_spec.freq = codecCtx-&amp;gt;sample_rate; &lt;br&gt;wanted_spec.callback = audio_callback; &lt;br&gt;wanted_spec.userdata = is; &lt;br&gt;if(SDL_OpenAudio(&amp;amp;wanted_spec, &amp;amp;spec) &amp;lt; 0) { &lt;br&gt;fprintf(stderr, “SDL_OpenAudio: %s\n”, SDL_GetError()); &lt;br&gt;return -1; &lt;br&gt;} &lt;br&gt;} &lt;br&gt;codec = avcodec_find_decoder(codecCtx-&amp;gt;codec_id); &lt;br&gt;if(!codec || (avcodec_open(codecCtx, codec) &amp;lt; 0)) { &lt;br&gt;fprintf(stderr, “Unsupported codec!\n”); &lt;br&gt;return -1; &lt;br&gt;} &lt;p&gt;switch(codecCtx-&amp;gt;codec_type) { &lt;br&gt;case CODEC_TYPE_AUDIO: &lt;br&gt;is-&amp;gt;audioStream = stream_index; &lt;br&gt;is-&amp;gt;audio_st = pFormatCtx-&amp;gt;streams[stream_index]; &lt;br&gt;is-&amp;gt;audio_buf_size = 0; &lt;br&gt;is-&amp;gt;audio_buf_index = 0; &lt;br&gt;memset(&amp;amp;is-&amp;gt;audio_pkt, 0, sizeof(is-&amp;gt;audio_pkt)); &lt;br&gt;packet_queue_init(&amp;amp;is-&amp;gt;audioq); &lt;br&gt;SDL_PauseAudio(0); &lt;br&gt;break; &lt;br&gt;case CODEC_TYPE_VIDEO: &lt;br&gt;is-&amp;gt;videoStream = stream_index; &lt;br&gt;is-&amp;gt;video_st = pFormatCtx-&amp;gt;streams[stream_index]; &lt;br&gt;packet_queue_init(&amp;amp;is-&amp;gt;videoq); &lt;br&gt;is-&amp;gt;video_tid = SDL_CreateThread(video_thread, is); &lt;br&gt;break; &lt;br&gt;default: &lt;br&gt;break; &lt;br&gt;} &lt;br&gt;} &lt;br&gt;这些代码和前面讲的基本上一样，只不过我们将对音频和视频的处理结合在了一起，值得注意的是我们将 &lt;br&gt;大的结构体VideoState作为audio callback的参数，而不是原来的CodecCtx，并把音频、视频流分别保存到了audio_st和video_st，同样，我们创建了视频队列并和音频队列一样初始化，然而最重要的是启动音频和视频处理线程： &lt;br&gt;SDL_PauseAudio(0); &lt;br&gt;break; &lt;p&gt;is-&amp;gt;video_tid = SDL_CreateThread(video_thread, is); &lt;br&gt;SDL_PauseAudio()上节已经讲过，下面介绍video_thread()函数 &lt;br&gt;首先回来看一下decode_thread()函数的后半部分，它基本上是一个for循环，主要完成读取一个packet然 &lt;p&gt;后将其添加到对应的队列中。 &lt;br&gt;for(;;) { &lt;br&gt;if(is-&amp;gt;quit) { &lt;br&gt;break; &lt;br&gt;} &lt;br&gt;// seek stuff goes here &lt;br&gt;if(is-&amp;gt;audioq.size &amp;gt; MAX_AUDIOQ_SIZE || &lt;br&gt;is-&amp;gt;videoq.size &amp;gt; MAX_VIDEOQ_SIZE) { &lt;br&gt;SDL_Delay(10); &lt;br&gt;continue; &lt;br&gt;} &lt;br&gt;if(av_read_frame(is-&amp;gt;pFormatCtx, packet) &amp;lt; 0) { &lt;br&gt;if(url_ferror(&amp;amp;pFormatCtx-&amp;gt;pb) == 0) { &lt;br&gt;SDL_Delay(100); &lt;br&gt;continue; &lt;br&gt;// 到此与作者的翻译接上。 &lt;br&gt;} else { &lt;br&gt;break; &lt;br&gt;} &lt;br&gt;} &lt;br&gt;// Is this a packet from the video stream? &lt;br&gt;if(packet-&amp;gt;stream_index == is-&amp;gt;videoStream) { &lt;br&gt;packet_queue_put(&amp;amp;is-&amp;gt;videoq, packet); &lt;br&gt;} else if(packet-&amp;gt;stream_index == is-&amp;gt;audioStream) { &lt;br&gt;packet_queue_put(&amp;amp;is-&amp;gt;audioq, packet); &lt;br&gt;} else { &lt;br&gt;av_free_packet(packet); &lt;br&gt;} &lt;br&gt;} &lt;p&gt;这里没有什么新东西，除了我们给音频和视频队列限定了一个最大值并且我们添加一个检测读错误的函数。格式上下文里面有一个叫做pb的 ByteIOContext类型结构体。这个结构体是用来保存一些低级的文件信息。函数url_ferror用来检测结构体并发现是否有些读取文件错误。 &lt;p&gt;在循环以后，我们的代码是用等待其余的程序结束和提示我们已经结束的。这些代码是有益的，因为它指示出了如何驱动事件－－后面我们将显示影像。 &lt;p&gt;while(!is-&amp;gt;quit) { &lt;p&gt;SDL_Delay(100); &lt;p&gt;} &lt;p&gt;fail: &lt;p&gt;if(1){ &lt;p&gt;SDL_Event event; &lt;p&gt;event.type = FF_QUIT_EVENT; &lt;p&gt;event.user.data1 = is; &lt;p&gt;SDL_PushEvent(&amp;amp;event); &lt;p&gt;} &lt;p&gt;return 0;  &lt;p&gt;我们使用SDL常量SDL_USEREVENT来从用户事件中得到值。第一个用户事件的值应当是SDL_USEREVENT，下一个是 SDL_USEREVENT＋1并且依此类推。在我们的程序中FF_QUIT_EVENT被定义成SDL_USEREVENT＋2。如果喜欢，我们也可以传递用户数据，在这里我们传递的是大结构体的指针。最后我们调用SDL_PushEvent()函数。在我们的事件分支中，我们只是像以前放入 SDL_QUIT_EVENT部分一样。我们将在自己的事件队列中详细讨论，现在只是确保我们正确放入了FF_QUIT_EVENT事件，我们将在后面捕捉到它并且设置我们的退出标志quit。 &lt;p&gt;得到帧：video_thread &lt;p&gt;当我们准备好解码器后，我们开始视频线程。这个线程从视频队列中读取包，把它解码成视频帧，然后调用queue_picture函数把处理好的帧放入到图片队列中: &lt;p&gt;int video_thread(void *arg) { &lt;p&gt;VideoState *is = (VideoState *)arg; &lt;p&gt;AVPacket pkt1, *packet = &amp;amp;pkt1; &lt;p&gt;int len1, frameFinished; &lt;p&gt;AVFrame *pFrame; &lt;p&gt;pFrame = avcodec_alloc_frame(); &lt;p&gt;for(;;) { &lt;p&gt;if(packet_queue_get(&amp;amp;is-&amp;gt;videoq, packet, 1) &amp;lt; 0) { &lt;p&gt;// means we quit getting packets &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;// Decode video frame &lt;p&gt;len1 = avcodec_decode_video(is-&amp;gt;video_st-&amp;gt;codec, pFrame, &amp;amp;frameFinished, &lt;p&gt;packet-&amp;gt;data, packet-&amp;gt;size); &lt;p&gt;// Did we get a video frame? &lt;p&gt;if(frameFinished) { &lt;p&gt;if(queue_picture(is, pFrame) &amp;lt; 0) { &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;} &lt;p&gt;av_free_packet(packet); &lt;p&gt;} &lt;p&gt;av_free(pFrame); &lt;p&gt;return 0; &lt;p&gt;}  &lt;p&gt;在这里的很多函数应该很熟悉吧。我们把avcodec_decode_video函数移到了这里，替换了一些参数，例如：我们把AVStream保存在我 们自己的大结构体中，所以我们可以从那里得到编解码器的信息。我们仅仅是不断的从视频队列中取包一直到有人告诉我们要停止或者出错为止。 &lt;p&gt;把帧队列化 &lt;p&gt;让我们看一下保存解码后的帧pFrame到图像队列中去的函数。因为我们的图像队列是SDL的覆盖的集合（基本上不用让视频显示函数再做计算了），我们需要把帧转换成相应的格式。我们保存到图像队列中的数据是我们自己做的一个结构体。 &lt;p&gt;typedef struct VideoPicture { &lt;p&gt;SDL_Overlay *bmp; &lt;p&gt;int width, height; &lt;p&gt;int allocated; &lt;p&gt;} VideoPicture;  &lt;p&gt;我们的大结构体有一个可以保存这些缓冲区。然而，我们需要自己来申请SDL_Overlay（注意：allocated标志会指明我们是否已经做了这个申请的动作与否）。 &lt;p&gt;为了使用这个队列，我们有两个指针－－写入指针和读取指针。我们也要保证一定数量的实际数据在缓冲中。要写入到队列中，我们先要等待缓冲清空以便于有位置来保存我们的VideoPicture。然后我们检查看我们是否已经申请到了一个可以写入覆盖的索引号。如果没有，我们要申请一段空间。我们也要重新申请缓冲如果窗口的大小已经改变。然而，为了避免被锁定，尽是避免在这里申请（我现在还不太清楚原因；我相信是为了避免在其它线程中调用SDL覆盖函数的原因）。 &lt;p&gt;int queue_picture(VideoState *is, AVFrame *pFrame) { &lt;p&gt;VideoPicture *vp; &lt;p&gt;int dst_pix_fmt; &lt;p&gt;AVPicture pict; &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;while(is-&amp;gt;pictq_size &amp;gt;= VIDEO_PICTURE_QUEUE_SIZE &amp;amp;&amp;amp; &lt;p&gt;!is-&amp;gt;quit) { &lt;p&gt;SDL_CondWait(is-&amp;gt;pictq_cond, is-&amp;gt;pictq_mutex); &lt;p&gt;} &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;if(is-&amp;gt;quit) &lt;p&gt;return -1; &lt;p&gt;// windex is set to 0 initially &lt;p&gt;vp = &amp;amp;is-&amp;gt;pictq[is-&amp;gt;pictq_windex]; &lt;p&gt;if(!vp-&amp;gt;bmp || &lt;p&gt;vp-&amp;gt;width != is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;width || &lt;p&gt;vp-&amp;gt;height != is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height) { &lt;p&gt;SDL_Event event; &lt;p&gt;vp-&amp;gt;allocated = 0; &lt;p&gt;event.type = FF_ALLOC_EVENT; &lt;p&gt;event.user.data1 = is; &lt;p&gt;SDL_PushEvent(&amp;amp;event); &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;while(!vp-&amp;gt;allocated &amp;amp;&amp;amp; !is-&amp;gt;quit) { &lt;p&gt;SDL_CondWait(is-&amp;gt;pictq_cond, is-&amp;gt;pictq_mutex); &lt;p&gt;} &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;if(is-&amp;gt;quit) { &lt;p&gt;return -1; &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;这里的事件机制与前面我们想要退出的时候看到的一样。我们已经定义了事件FF_ALLOC_EVENT作为SDL_USEREVENT。我们把事件发到事件队列中然后等待申请内存的函数设置好条件变量。 &lt;p&gt;让我们来看一看如何来修改事件循环： &lt;p&gt;for(;;) { &lt;p&gt;SDL_WaitEvent(&amp;amp;event); &lt;p&gt;switch(event.type) { &lt;p&gt;case FF_ALLOC_EVENT: &lt;p&gt;alloc_picture(event.user.data1); &lt;p&gt;break;  &lt;p&gt;记住event.user.data1是我们的大结构体。就这么简单。让我们看一下alloc_picture()函数： &lt;p&gt;void alloc_picture(void *userdata) { &lt;p&gt;VideoState *is = (VideoState *)userdata; &lt;p&gt;VideoPicture *vp; &lt;p&gt;vp = &amp;amp;is-&amp;gt;pictq[is-&amp;gt;pictq_windex]; &lt;p&gt;if(vp-&amp;gt;bmp) { &lt;p&gt;// we already have one make another, bigger/smaller &lt;p&gt;SDL_FreeYUVOverlay(vp-&amp;gt;bmp); &lt;p&gt;} &lt;p&gt;// Allocate a place to put our YUV image on that screen &lt;p&gt;vp-&amp;gt;bmp = SDL_CreateYUVOverlay(is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;width, &lt;p&gt;is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height, &lt;p&gt;SDL_YV12_OVERLAY, &lt;p&gt;screen); &lt;p&gt;vp-&amp;gt;width = is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;width; &lt;p&gt;vp-&amp;gt;height = is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height; &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;vp-&amp;gt;allocated = 1; &lt;p&gt;SDL_CondSignal(is-&amp;gt;pictq_cond); &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;}  &lt;p&gt;你可以看到我们把SDL_CreateYUVOverlay函数从主循环中移到了这里。这段代码应该完全可以自我注释。记住我们把高度和宽度保存到VideoPicture结构体中因为我们需要保存我们的视频的大小没有因为某些原因而改变。 &lt;p&gt;好，我们几乎已经全部解决并且可以申请到YUV覆盖和准备好接收图像。让我们回顾一下queue_picture并看一个拷贝帧到覆盖的代码。你应该能认出其中的一部分： &lt;p&gt;int queue_picture(VideoState *is, AVFrame *pFrame) { &lt;p&gt;if(vp-&amp;gt;bmp) { &lt;p&gt;SDL_LockYUVOverlay(vp-&amp;gt;bmp); &lt;p&gt;dst_pix_fmt = PIX_FMT_YUV420P; &lt;p&gt;pict.data[0] = vp-&amp;gt;bmp-&amp;gt;pixels[0]; &lt;p&gt;pict.data[1] = vp-&amp;gt;bmp-&amp;gt;pixels[2]; &lt;p&gt;pict.data[2] = vp-&amp;gt;bmp-&amp;gt;pixels[1]; &lt;p&gt;pict.linesize[0] = vp-&amp;gt;bmp-&amp;gt;pitches[0]; &lt;p&gt;pict.linesize[1] = vp-&amp;gt;bmp-&amp;gt;pitches[2]; &lt;p&gt;pict.linesize[2] = vp-&amp;gt;bmp-&amp;gt;pitches[1]; &lt;p&gt;// Convert the image into YUV format that SDL uses &lt;p&gt;img_convert(&amp;amp;pict, dst_pix_fmt, &lt;p&gt;(AVPicture *)pFrame, is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;pix_fmt, &lt;p&gt;is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;width, is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;height); &lt;p&gt;SDL_UnlockYUVOverlay(vp-&amp;gt;bmp); &lt;p&gt;if(++is-&amp;gt;pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) { &lt;p&gt;is-&amp;gt;pictq_windex = 0; &lt;p&gt;} &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;is-&amp;gt;pictq_size++; &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;} &lt;p&gt;return 0; &lt;p&gt;}  &lt;p&gt;这部分代码和前面用到的一样，主要是简单的用我们的帧来填充YUV覆盖。最后一点只是简单的给队列加1。这个队列在写的时候会一直写入到满为止，在读的时候会一直读空为止。因此所有的都依赖于is-&amp;gt;pictq_size值，这要求我们必需要锁定它。这里我们做的是增加写指针（在必要的时候采用轮转的方式），然后锁定队列并且增加尺寸。现在我们的读者函数将会知道队列中有了更多的信息，当队列满的时候，我们的写入函数也会知道。 &lt;p&gt;显示视频 &lt;p&gt;这就是我们的视频线程。现在我们看过了几乎所有的线程除了一个－－记得我们调用schedule_refresh()函数吗？让我们看一下实际中是如何做的： &lt;p&gt;static void schedule_refresh(VideoState *is, int delay) { &lt;p&gt;SDL_AddTimer(delay, sdl_refresh_timer_cb, is); &lt;p&gt;}  &lt;p&gt;函数SDL_AddTimer()是SDL中的一个定时（特定的毫秒）执行用户定义的回调函数（可以带一些参数user data）的简单函数。我们将用这个函数来定时刷新视频－－每次我们调用这个函数的时候，它将设置一个定时器来触发定时事件来把一帧从图像队列中显示到屏幕上。 &lt;p&gt;但是，让我们先触发那个事件。 &lt;p&gt;static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque) { &lt;p&gt;SDL_Event event; &lt;p&gt;event.type = FF_REFRESH_EVENT; &lt;p&gt;event.user.data1 = opaque; &lt;p&gt;SDL_PushEvent(&amp;amp;event); &lt;p&gt;return 0; &lt;p&gt;}  &lt;p&gt;这里向队列中写入了一个现在很熟悉的事件。FF_REFRESH_EVENT被定义成SDL_USEREVENT+1。要注意的一件事是当返回0的时候，SDL停止定时器，于是回调就不会再发生。 &lt;p&gt;现在我们产生了一个FF_REFRESH_EVENT事件，我们需要在事件循环中处理它： &lt;p&gt;for(;;) { &lt;p&gt;SDL_WaitEvent(&amp;amp;event); &lt;p&gt;switch(event.type) { &lt;p&gt;case FF_REFRESH_EVENT: &lt;p&gt;video_refresh_timer(event.user.data1); &lt;p&gt;break;  &lt;p&gt;于是我们就运行到了这个函数，在这个函数中会把数据从图像队列中取出： &lt;p&gt;void video_refresh_timer(void *userdata) { &lt;p&gt;VideoState *is = (VideoState *)userdata; &lt;p&gt;VideoPicture *vp; &lt;p&gt;if(is-&amp;gt;video_st) { &lt;p&gt;if(is-&amp;gt;pictq_size == 0) { &lt;p&gt;schedule_refresh(is, 1); &lt;p&gt;} else { &lt;p&gt;vp = &amp;amp;is-&amp;gt;pictq[is-&amp;gt;pictq_rindex]; &lt;p&gt;schedule_refresh(is, 80); &lt;p&gt;video_display(is); &lt;p&gt;if(++is-&amp;gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { &lt;p&gt;is-&amp;gt;pictq_rindex = 0; &lt;p&gt;} &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;is-&amp;gt;pictq_size–; &lt;p&gt;SDL_CondSignal(is-&amp;gt;pictq_cond); &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;} &lt;p&gt;} else { &lt;p&gt;schedule_refresh(is, 100); &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;现在，这只是一个极其简单的函数：当队列中有数据的时候，他从其中获得数据，为下一帧设置定时器，调用video_display函数来真正显示图像到屏幕上，然后把队列读索引值加1，并且把队列的尺寸size减1。你可能会注意到在这个函数中我们并没有真正对vp做一些实际的动作，原因是这样的：我们将在后面处理。我们将在后面同步音频和视频的时候用它来访问时间信息。你会在这里看到这个注释信息”timing密码here”。那里我们将讨论什么时候显示下一帧视频，然后把相应的值写入到schedule_refresh()函数中。现在我们只是随便写入一个值80。从技术上来讲，你可以猜测并验证这个值，并且为每个电影重新编译程序，但是：1）过一段时间它会漂移；2）这种方式是很笨的。我们将在后面来讨论它。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755257.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755257.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755258.html</id><title type="text">ffmpeg文档5：同步视频</title><summary type="text">指导5：同步视频 如何同步视频 前面整个的一段时间，我们有了一个几乎无用的电影播放器。当然，它能播放视频，也能播放音频，但是它还不能被称为一部电影。那么我们还要做什么呢？ PTS和DTS 幸运的是，音...</summary><published>2010-06-10T01:08:00Z</published><updated>2010-06-10T01:08:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755258.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755258.html"/><content type="html">&lt;p&gt;指导5：同步视频 &lt;p&gt;如何同步视频 &lt;p&gt;前面整个的一段时间，我们有了一个几乎无用的电影播放器。当然，它能播放视频，也能播放音频，但是它还不能被称为一部电影。那么我们还要做什么呢？ &lt;p&gt;PTS和DTS &lt;p&gt;幸运的是，音频和视频流都有一些关于以多快速度和什么时间来播放它们的信息在里面。音频流有采样，视频流有每秒的帧率。然而，如果我们只是简单的通过数帧和乘以帧率的方式来同步视频，那么就很有可能会失去同步。于是作为一种补充，在流中的包有种叫做DTS（解码时间戳）和PTS（显示时间戳）的机制。为了这两个参数，你需要了解电影存放的方式。像MPEG等格式，使用被叫做B帧（B表示双向bidrectional）的方式。另外两种帧被叫做I帧和P帧（I表示关键帧，P表示预测帧）。I帧包含了某个特定的完整图像。P帧依赖于前面的I帧和P帧并且使用比较或者差分的方式来编码。B帧与P帧有点类似，但是它是依赖于前面和后面的帧的信息的。这也就解释了为什么我们可能在调用avcodec_decode_video以后会得不到一帧图像。 &lt;p&gt;所以对于一个电影，帧是这样来显示的：I B B P。现在我们需要在显示B帧之前知道P帧中的信息。因此，帧可能会按照这样的方式来存储：IPBB。这就是为什么我们会有一个解码时间戳和一个显示时间戳的原因。解码时间戳告诉我们什么时候需要解码，显示时间戳告诉我们什么时候需要显示。所以，在这种情况下，我们的流可以是这样的： &lt;p&gt;PTS: 1 4 2 3 &lt;p&gt;DTS: 1 2 3 4 &lt;p&gt;Stream: I P B B  &lt;p&gt;通常PTS和DTS只有在流中有B帧的时候会不同。 &lt;p&gt;当我们调用av_read_frame()得到一个包的时候，PTS和DTS的信息也会保存在包中。但是我们真正想要的PTS是我们刚刚解码出来的原始帧的PTS，这样我们才能知道什么时候来显示它。然而，我们从avcodec_decode_video()函数中得到的帧只是一个AVFrame，其中并没有包含有用的PTS值（注意：AVFrame并没有包含时间戳信息，但当我们等到帧的时候并不是我们想要的样子）。然而，ffmpeg重新排序包以便于被avcodec_decode_video()函数处理的包的DTS可以总是与其返回的PTS相同。但是，另外的一个警告是：我们也并不是总能得到这个信息。 &lt;p&gt;不用担心，因为有另外一种办法可以找到帖的PTS，我们可以让程序自己来重新排序包。我们保存一帧的第一个包的PTS：这将作为整个这一帧的PTS。我们可以通过函数avcodec_decode_video()来计算出哪个包是一帧的第一个包。怎样实现呢？任何时候当一个包开始一帧的时候，avcodec_decode_video()将调用一个函数来为一帧申请一个缓冲。当然，ffmpeg允许我们重新定义那个分配内存的函数。所以我们制作了一个新的函数来保存一个包的时间戳。 &lt;p&gt;当然，尽管那样，我们可能还是得不到一个正确的时间戳。我们将在后面处理这个问题。 &lt;p&gt;同步 &lt;p&gt;现在，知道了什么时候来显示一个视频帧真好，但是我们怎样来实际操作呢？这里有个主意：当我们显示了一帧以后，我们计算出下一帧显示的时间。然后我们简单的设置一个新的定时器来。你可能会想，我们检查下一帧的PTS值而不是系统时钟来看超时是否会到。这种方式可以工作，但是有两种情况要处理。 &lt;p&gt;首先，要知道下一个PTS是什么。现在我们能添加视频速率到我们的PTS中－－太对了！然而，有些电影需要帧重复。这意味着我们重复播放当前的帧。这将导致程序显示下一帧太快了。所以我们需要计算它们。 &lt;p&gt;第二，正如程序现在这样，视频和音频播放很欢快，一点也不受同步的影响。如果一切都工作得很好的话，我们不必担心。但是，你的电脑并不是最好的，很多视频文件也不是完好的。所以，我们有三种选择：同步音频到视频，同步视频到音频，或者都同步到外部时钟（例如你的电脑时钟）。从现在开始，我们将同步视频到音频。 &lt;p&gt;写代码：获得帧的时间戳 &lt;p&gt;现在让我们到代码中来做这些事情。我们将需要为我们的大结构体添加一些成员，但是我们会根据需要来做。首先，让我们看一下视频线程。记住，在这里我们得到了解码线程输出到队列中的包。这里我们需要的是从avcodec_decode_video函数中得到帧的时间戳。我们讨论的第一种方式是从上次处理的包中得到DTS，这是很容易的： &lt;p&gt;double pts; &lt;p&gt;for(;;) { &lt;p&gt;if(packet_queue_get(&amp;amp;is-&amp;gt;videoq, packet, 1) &amp;lt; 0) { &lt;p&gt;// means we quit getting packets &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;pts = 0; &lt;p&gt;// Decode video frame &lt;p&gt;len1 = avcodec_decode_video(is-&amp;gt;video_st-&amp;gt;codec, &lt;p&gt;pFrame, &amp;amp;frameFinished, &lt;p&gt;packet-&amp;gt;data, packet-&amp;gt;size); &lt;p&gt;if(packet-&amp;gt;dts != AV_NOPTS_VALUE) { &lt;p&gt;pts = packet-&amp;gt;dts; &lt;p&gt;} else { &lt;p&gt;pts = 0; &lt;p&gt;} &lt;p&gt;pts *= av_q2d(is-&amp;gt;video_st-&amp;gt;time_base);  &lt;p&gt;如果我们得不到PTS就把它设置为0。 &lt;p&gt;好，那是很容易的。但是我们所说的如果包的DTS不能帮到我们，我们需要使用这一帧的第一个包的PTS。我们通过让ffmpeg使用我们自己的申请帧程序来实现。下面的是函数的格式： &lt;p&gt;int get_buffer(struct AVCodecContext *c, AVFrame *pic); &lt;p&gt;void release_buffer(struct AVCodecContext *c, AVFrame *pic);  &lt;p&gt;申请函数没有告诉我们关于包的任何事情，所以我们要自己每次在得到一个包的时候把PTS保存到一个全局变量中去。我们自己以读到它。然后，我们把值保存到AVFrame结构体难理解的变量中去。所以一开始，这就是我们的函数： &lt;p&gt;uint64_t global_video_pkt_pts = AV_NOPTS_VALUE; &lt;p&gt;int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) { &lt;p&gt;int ret = avcodec_default_get_buffer(c, pic); &lt;p&gt;uint64_t *pts = av_malloc(sizeof(uint64_t)); &lt;p&gt;*pts = global_video_pkt_pts; &lt;p&gt;pic-&amp;gt;opaque = pts; &lt;p&gt;return ret; &lt;p&gt;} &lt;p&gt;void our_release_buffer(struct AVCodecContext *c, AVFrame *pic) { &lt;p&gt;if(pic) av_freep(&amp;amp;pic-&amp;gt;opaque); &lt;p&gt;avcodec_default_release_buffer(c, pic); &lt;p&gt;}  &lt;p&gt;函数avcodec_default_get_buffer和avcodec_default_release_buffer是ffmpeg中默认的申请缓冲的函数。函数av_freep是一个内存管理函数，它不但把内存释放而且把指针设置为NULL。 &lt;p&gt;现在到了我们流打开的函数（stream_component_open），我们添加这几行来告诉ffmpeg如何去做： &lt;p&gt;codecCtx-&amp;gt;get_buffer = our_get_buffer; &lt;p&gt;codecCtx-&amp;gt;release_buffer = our_release_buffer;  &lt;p&gt;现在我们必需添加代码来保存PTS到全局变量中，然后在需要的时候来使用它。我们的代码现在看起来应该是这样子： &lt;p&gt;for(;;) { &lt;p&gt;if(packet_queue_get(&amp;amp;is-&amp;gt;videoq, packet, 1) &amp;lt; 0) { &lt;p&gt;// means we quit getting packets &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;pts = 0; &lt;p&gt;// Save global pts to be stored in pFrame in first call &lt;p&gt;global_video_pkt_pts = packet-&amp;gt;pts; &lt;p&gt;// Decode video frame &lt;p&gt;len1 = avcodec_decode_video(is-&amp;gt;video_st-&amp;gt;codec, pFrame, &amp;amp;frameFinished, &lt;p&gt;packet-&amp;gt;data, packet-&amp;gt;size); &lt;p&gt;if(packet-&amp;gt;dts == AV_NOPTS_VALUE &lt;p&gt;&amp;amp;&amp;amp; pFrame-&amp;gt;opaque &amp;amp;&amp;amp; *(uint64_t*)pFrame-&amp;gt;opaque != AV_NOPTS_VALUE) { &lt;p&gt;pts = *(uint64_t *)pFrame-&amp;gt;opaque; &lt;p&gt;} else if(packet-&amp;gt;dts != AV_NOPTS_VALUE) { &lt;p&gt;pts = packet-&amp;gt;dts; &lt;p&gt;} else { &lt;p&gt;pts = 0; &lt;p&gt;} &lt;p&gt;pts *= av_q2d(is-&amp;gt;video_st-&amp;gt;time_base);  &lt;p&gt;技术提示：你可能已经注意到我们使用int64来表示PTS。这是因为PTS是以整型来保存的。这个值是一个时间戳相当于时间的度量，用来以流的 time_base为单位进行时间度量。例如，如果一个流是24帧每秒，值为42的PTS表示这一帧应该排在第42个帧的位置如果我们每秒有24帧（这里并不完全正确）。 &lt;p&gt;我们可以通过除以帧率来把这个值转化为秒。流中的time_base值表示1/framerate（对于固定帧率来说），所以得到了以秒为单位的PTS，我们需要乘以time_base。 &lt;p&gt;写代码：使用PTS来同步 &lt;p&gt;现在我们得到了PTS。我们要注意前面讨论到的两个同步问题。我们将定义一个函数叫做synchronize_video，它可以更新同步的PTS。这个函数也能最终处理我们得不到PTS的情况。同时我们要知道下一帧的时间以便于正确设置刷新速率。我们可以使用内部的反映当前视频已经播放时间的时钟 video_clock来完成这个功能。我们把这些值添加到大结构体中。 &lt;p&gt;typedef struct VideoState { &lt;p&gt;double video_clock; ///  &lt;p&gt;下面的是函数synchronize_video，它可以很好的自我注释： &lt;p&gt;double synchronize_video(VideoState *is, AVFrame *src_frame, double pts) { &lt;p&gt;double frame_delay; &lt;p&gt;if(pts != 0) { &lt;p&gt;is-&amp;gt;video_clock = pts; &lt;p&gt;} else { &lt;p&gt;pts = is-&amp;gt;video_clock; &lt;p&gt;} &lt;p&gt;frame_delay = av_q2d(is-&amp;gt;video_st-&amp;gt;codec-&amp;gt;time_base); &lt;p&gt;frame_delay += src_frame-&amp;gt;repeat_pict * (frame_delay * 0.5); &lt;p&gt;is-&amp;gt;video_clock += frame_delay; &lt;p&gt;return pts; &lt;p&gt;}  &lt;p&gt;你也会注意到我们也计算了重复的帧。 &lt;p&gt;现在让我们得到正确的PTS并且使用queue_picture来队列化帧，添加一个新的时间戳参数pts： &lt;p&gt;// Did we get a video frame? &lt;p&gt;if(frameFinished) { &lt;p&gt;pts = synchronize_video(is, pFrame, pts); &lt;p&gt;if(queue_picture(is, pFrame, pts) &amp;lt; 0) { &lt;p&gt;break; &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;对于queue_picture来说唯一改变的事情就是我们把时间戳值pts保存到VideoPicture结构体中，我们我们必需添加一个时间戳变量到结构体中并且添加一行代码： &lt;p&gt;typedef struct VideoPicture { &lt;p&gt;… &lt;p&gt;double pts; &lt;p&gt;} &lt;p&gt;int queue_picture(VideoState *is, AVFrame *pFrame, double pts) { &lt;p&gt;… stuff … &lt;p&gt;if(vp-&amp;gt;bmp) { &lt;p&gt;… convert picture … &lt;p&gt;vp-&amp;gt;pts = pts; &lt;p&gt;… alert queue … &lt;p&gt;}  &lt;p&gt;现在我们的图像队列中的所有图像都有了正确的时间戳值，所以让我们看一下视频刷新函数。你会记得上次我们用80ms的刷新时间来欺骗它。那么，现在我们将会算出实际的值。 &lt;p&gt;我们的策略是通过简单计算前一帧和现在这一帧的时间戳来预测出下一个时间戳的时间。同时，我们需要同步视频到音频。我们将设置一个音频时间audio clock；一个内部值记录了我们正在播放的音频的位置。就像从任意的mp3播放器中读出来的数字一样。既然我们把视频同步到音频，视频线程使用这个值来算出是否太快还是太慢。 &lt;p&gt;我们将在后面来实现这些代码；现在我们假设我们已经有一个可以给我们音频时间的函数get_audio_clock。一旦我们有了这个值，我们在音频和视频失去同步的时候应该做些什么呢？简单而有点笨的办法是试着用跳过正确帧或者其它的方式来解决。作为一种替代的手段，我们会调整下次刷新的值；如果时间戳太落后于音频时间，我们加倍计算延迟。如果时间戳太领先于音频时间，我们将尽可能快的刷新。既然我们有了调整过的时间和延迟，我们将把它和我们通过 frame_timer计算出来的时间进行比较。这个帧时间frame_timer将会统计出电影播放中所有的延时。换句话说，这个 frame_timer就是指我们什么时候来显示下一帧。我们简单的添加新的帧定时器延时，把它和电脑的系统时间进行比较，然后使用那个值来调度下一次刷新。这可能有点难以理解，所以请认真研究代码： &lt;p&gt;void video_refresh_timer(void *userdata) { &lt;p&gt;VideoState *is = (VideoState *)userdata; &lt;p&gt;VideoPicture *vp; &lt;p&gt;double actual_delay, delay, sync_threshold, ref_clock, diff; &lt;p&gt;if(is-&amp;gt;video_st) { &lt;p&gt;if(is-&amp;gt;pictq_size == 0) { &lt;p&gt;schedule_refresh(is, 1); &lt;p&gt;} else { &lt;p&gt;vp = &amp;amp;is-&amp;gt;pictq[is-&amp;gt;pictq_rindex]; &lt;p&gt;delay = vp-&amp;gt;pts – is-&amp;gt;frame_last_pts; &lt;p&gt;if(delay &amp;lt;= 0 || delay &amp;gt;= 1.0) { &lt;p&gt;delay = is-&amp;gt;frame_last_delay; &lt;p&gt;} &lt;p&gt;is-&amp;gt;frame_last_delay = delay; &lt;p&gt;is-&amp;gt;frame_last_pts = vp-&amp;gt;pts; &lt;p&gt;ref_clock = get_audio_clock(is); &lt;p&gt;diff = vp-&amp;gt;pts – ref_clock; &lt;p&gt;sync_threshold = (delay &amp;gt; AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD; &lt;p&gt;if(fabs(diff) &amp;lt; AV_NOSYNC_THRESHOLD) { &lt;p&gt;if(diff &amp;lt;= -sync_threshold) { &lt;p&gt;delay = 0; &lt;p&gt;} else if(diff &amp;gt;= sync_threshold) { &lt;p&gt;delay = 2 * delay; &lt;p&gt;} &lt;p&gt;} &lt;p&gt;is-&amp;gt;frame_timer += delay; &lt;p&gt;actual_delay = is-&amp;gt;frame_timer – (av_gettime() / 1000000.0); &lt;p&gt;if(actual_delay &amp;lt; 0.010) { &lt;p&gt;actual_delay = 0.010; &lt;p&gt;} &lt;p&gt;schedule_refresh(is, (int)(actual_delay * 1000 + 0.5)); &lt;p&gt;video_display(is); &lt;p&gt;if(++is-&amp;gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { &lt;p&gt;is-&amp;gt;pictq_rindex = 0; &lt;p&gt;} &lt;p&gt;SDL_LockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;is-&amp;gt;pictq_size–; &lt;p&gt;SDL_CondSignal(is-&amp;gt;pictq_cond); &lt;p&gt;SDL_UnlockMutex(is-&amp;gt;pictq_mutex); &lt;p&gt;} &lt;p&gt;} else { &lt;p&gt;schedule_refresh(is, 100); &lt;p&gt;} &lt;p&gt;}  &lt;p&gt;我们在这里做了很多检查：首先，我们保证现在的时间戳和上一个时间戳之间的处以delay是有意义的。如果不是的话，我们就猜测着用上次的延迟。接着，我们有一个同步阈值，因为在同步的时候事情并不总是那么完美的。在ffplay中使用0.01作为它的值。我们也保证阈值不会比时间戳之间的间隔短。最后，我们把最小的刷新值设置为10毫秒。 &lt;p&gt;（这句不知道应该放在哪里）事实上这里我们应该跳过这一帧，但是我们不想为此而烦恼。  &lt;p&gt;我们给大结构体添加了很多的变量，所以不要忘记检查一下代码。同时也不要忘记在函数streame_component_open中初始化帧时间frame_timer和前面的帧延迟frame delay： &lt;p&gt;is-&amp;gt;frame_timer = (double)av_gettime() / 1000000.0; &lt;p&gt;is-&amp;gt;frame_last_delay = 40e-3;  &lt;p&gt;同步：声音时钟 &lt;p&gt;现在让我们看一下怎样来得到声音时钟。我们可以在声音解码函数audio_decode_frame中更新时钟时间。现在，请记住我们并不是每次调用这个函数的时候都在处理新的包，所以有我们要在两个地方更新时钟。第一个地方是我们得到新的包的时候：我们简单的设置声音时钟为这个包的时间戳。然后，如果一个包里有许多帧，我们通过样本数和采样率来计算，所以当我们得到包的时候： &lt;p&gt;if(pkt-&amp;gt;pts != AV_NOPTS_VALUE) { &lt;p&gt;is-&amp;gt;audio_clock = av_q2d(is-&amp;gt;audio_st-&amp;gt;time_base)*pkt-&amp;gt;pts; &lt;p&gt;}  &lt;p&gt;然后当我们处理这个包的时候： &lt;p&gt;pts = is-&amp;gt;audio_clock; &lt;p&gt;*pts_ptr = pts; &lt;p&gt;n = 2 * is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;channels; &lt;p&gt;is-&amp;gt;audio_clock += (double)data_size / &lt;p&gt;(double)(n * is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;sample_rate);  &lt;p&gt;一点细节：临时函数被改成包含pts_ptr，所以要保证你已经改了那些。这时的pts_ptr是一个用来通知audio_callback函数当前声音包的时间戳的指针。这将在下次用来同步声音和视频。 &lt;p&gt;现在我们可以最后来实现我们的get_audio_clock函数。它并不像得到is-&amp;gt;audio_clock值那样简单。注意我们会在每次处理它的时候设置声音时间戳，但是如果你看了audio_callback函数，它花费了时间来把数据从声音包中移到我们的输出缓冲区中。这意味着我们声音时钟中记录的时间比实际的要早太多。所以我们必须要检查一下我们还有多少没有写入。下面是完整的代码： &lt;p&gt;double get_audio_clock(VideoState *is) { &lt;p&gt;double pts; &lt;p&gt;int hw_buf_size, bytes_per_sec, n; &lt;p&gt;pts = is-&amp;gt;audio_clock; &lt;p&gt;hw_buf_size = is-&amp;gt;audio_buf_size – is-&amp;gt;audio_buf_index; &lt;p&gt;bytes_per_sec = 0; &lt;p&gt;n = is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;channels * 2; &lt;p&gt;if(is-&amp;gt;audio_st) { &lt;p&gt;bytes_per_sec = is-&amp;gt;audio_st-&amp;gt;codec-&amp;gt;sample_rate * n; &lt;p&gt;} &lt;p&gt;if(bytes_per_sec) { &lt;p&gt;pts -= (double)hw_buf_size / bytes_per_sec; &lt;p&gt;} &lt;p&gt;return pts; &lt;p&gt;}  &lt;p&gt;你应该知道为什么这个函数可以正常工作了;) &lt;p&gt;这就是了！让我们编译它： &lt;p&gt;gcc -o tutorial05 tutorial05.c -lavutil -lavformat -lavcodec -lz -lm`sdl-config –cflags –libs`  &lt;p&gt;最后，你可以使用我们自己的电影播放器来看电影了。下次我们将看一下声音同步，然后接下来的指导我们会讨论查询。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755258.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755258.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755254.html</id><title type="text">ffmpeg文档2:输出到屏幕</title><summary type="text">SDL和视频 为了在屏幕上显示，我们将使用SDL.SDL是Simple Direct Layer的缩写。它是一个出色的多媒体库，适用于多平台，并且被用在许多工程中。你可以从它的官方网站的网址 http...</summary><published>2010-06-10T01:07:00Z</published><updated>2010-06-10T01:07:00Z</updated><author><name>JesseZhao</name><uri>http://www.cnblogs.com/jessezhao/</uri></author><link rel="alternate" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755254.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755254.html"/><content type="html">&lt;p&gt;SDL和视频 &lt;p&gt;为了在屏幕上显示，我们将使用SDL.SDL是Simple Direct Layer的缩写。它是一个出色的多媒体库，适用于多平台，并且被用在许多工程中。你可以从它的官方网站的网址 &lt;a href="http://www.libsdl.org/"&gt;http://www.libsdl.org/&lt;/a&gt;上来得到这个库的源代码或者如果有可能的话你可以直接下载开发包到你的操作系统中。按照这个指导，你将需要编译这个库。（剩下的几个指导中也是一样） &lt;p&gt;SDL库中有许多种方式来在屏幕上绘制图形，而且它有一个特殊的方式来在屏幕上显示图像――这种方式叫做YUV覆盖。YUV（从技术上来讲并不叫YUV而是叫做YCbCr）是一种类似于RGB方式的存储原始图像的格式。粗略的讲，Y是亮度分量，U和V是色度分量。（这种格式比RGB复杂的多，因为很多的颜色信息被丢弃了，而且你可以每2个Y有1个U和1个V）。SDL的YUV覆盖使用一组原始的YUV数据并且在屏幕上显示出他们。它可以允许4种不同的 YUV格式，但是其中的YV12是最快的一种。还有一个叫做YUV420P的YUV格式，它和YV12是一样的，除了U和V分量的位置被调换了以外。 420意味着它以4：2：0的比例进行了二次抽样，基本上就意味着1个颜色分量对应着4个亮度分量。所以它的色度信息只有原来的1/4。这是一种节省带宽的好方式，因为人眼感觉不到这种变化。在名称中的P表示这种格式是平面的――简单的说就是Y，U和V分量分别在不同的数组中。FFMPEG可以把图像格式转换为YUV420P，但是现在很多视频流的格式已经是YUV420P的了或者可以被很容易的转换成YUV420P格式。 &lt;p&gt;于是，我们现在计划把指导1中的SaveFrame()函数替换掉，让它直接输出我们的帧到屏幕上去。但一开始我们必需要先看一下如何使用SDL库。首先我们必需先包含SDL库的头文件并且初始化它。 &lt;p&gt;#include &amp;lt;SDL.h&amp;gt; &lt;p&gt;#include &amp;lt;SDL_thread.h&amp;gt; &lt;p&gt;if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { &lt;p&gt;fprintf(stderr, “Could not initialize SDL – %s\n”, SDL_GetError()); &lt;p&gt;exit(1); &lt;p&gt;}  &lt;p&gt;SDL_Init()函数告诉了SDL库，哪些特性我们将要用到。当然SDL_GetError()是一个用来手工除错的函数。 &lt;p&gt;创建一个显示 &lt;p&gt;现在我们需要在屏幕上的一个地方放上一些东西。在SDL中显示图像的基本区域叫做面surface。 &lt;p&gt;SDL_Surface *screen; &lt;p&gt;screen = SDL_SetVideoMode(pCodecCtx-&amp;gt;width, pCodecCtx-&amp;gt;height, 0, 0); &lt;p&gt;if(!screen) { &lt;p&gt;fprintf(stderr, “SDL: could not set video mode – exiting\n”); &lt;p&gt;exit(1); &lt;p&gt;}  &lt;p&gt;这就创建了一个给定高度和宽度的屏幕。下一个选项是屏幕的颜色深度――0表示使用和当前一样的深度。（这个在OS X系统上不能正常工作，原因请看源代码） &lt;p&gt;现在我们在屏幕上来创建一个YUV覆盖以便于我们输入视频上去： &lt;p&gt;SDL_Overlay *bmp; &lt;p&gt;bmp = SDL_CreateYUVOverlay(pCodecCtx-&amp;gt;width, pCodecCtx-&amp;gt;height, &lt;p&gt;SDL_YV12_OVERLAY, screen);  &lt;p&gt;正如前面我们所说的，我们使用YV12来显示图像。 &lt;p&gt;显示图像 &lt;p&gt;前面那些都是很简单的。现在我们需要来显示图像。让我们看一下是如何来处理完成后的帧的。我们将原来对RGB处理的方式，并且替换SaveFrame() 为显示到屏幕上的代码。为了显示到屏幕上，我们将先建立一个AVPicture结构体并且设置其数据指针和行尺寸来为我们的YUV覆盖服务： &lt;p&gt;if(frameFinished) { &lt;p&gt;SDL_LockYUVOverlay(bmp); &lt;p&gt;AVPicture pict; &lt;p&gt;pict.data[0] = bmp-&amp;gt;pixels[0]; &lt;p&gt;pict.data[1] = bmp-&amp;gt;pixels[2]; &lt;p&gt;pict.data[2] = bmp-&amp;gt;pixels[1]; &lt;p&gt;pict.linesize[0] = bmp-&amp;gt;pitches[0]; &lt;p&gt;pict.linesize[1] = bmp-&amp;gt;pitches[2]; &lt;p&gt;pict.linesize[2] = bmp-&amp;gt;pitches[1]; &lt;p&gt;// Convert the image into YUV format that SDL uses &lt;p&gt;img_convert(&amp;amp;pict, PIX_FMT_YUV420P, &lt;p&gt;(AVPicture *)pFrame, pCodecCtx-&amp;gt;pix_fmt, &lt;p&gt;pCodecCtx-&amp;gt;width, pCodecCtx-&amp;gt;height); &lt;p&gt;SDL_UnlockYUVOverlay(bmp); &lt;p&gt;}  &lt;p&gt;首先，我们锁定这个覆盖，因为我们将要去改写它。这是一个避免以后发生问题的好习惯。正如前面所示的，这个AVPicture结构体有一个数据指针指向一个有4个元素的指针数据。由于我们处理的是YUV420P，所以我们只需要3个通道即只要三组数据。其它的格式可能需要第四个指针来表示alpha通道或者其它参数。行尺寸正如它的名字表示的意义一样。在YUV覆盖中相同功能的结构体是像素pixel和程度pitch。（程度pitch是在SDL里用来表示指定行数据宽度的值）。所以我们现在做的是让我们的覆盖中的pict.data中的三个指针有一个指向必要的空间的地址。类似的，我们可以直接从覆盖中得到行尺寸信息。像前面一样我们使用img_convert来把格式转换成PIX_FMT_YUV420P。 &lt;p&gt;绘制图像 &lt;p&gt;但我们仍然需要告诉SDL如何来实际显示我们给的数据。我们也会传递一个表明电影位置、宽度、高度和缩放大小的矩形参数给SDL的函数。这样，SDL为我们做缩放并且它可以通过显卡的帮忙来进行快速缩放。 &lt;p&gt;SDL_Rect rect; &lt;p&gt;if(frameFinished) { &lt;p&gt;// Convert the image into YUV format that SDL uses &lt;p&gt;img_convert(&amp;amp;pict, PIX_FMT_YUV420P, &lt;p&gt;(AVPicture *)pFrame, pCodecCtx-&amp;gt;pix_fmt, &lt;p&gt;pCodecCtx-&amp;gt;width, pCodecCtx-&amp;gt;height); &lt;p&gt;SDL_UnlockYUVOverlay(bmp); &lt;p&gt;rect.x = 0; &lt;p&gt;rect.y = 0; &lt;p&gt;rect.w = pCodecCtx-&amp;gt;width; &lt;p&gt;rect.h = pCodecCtx-&amp;gt;height; &lt;p&gt;SDL_DisplayYUVOverlay(bmp, &amp;amp;rect); &lt;p&gt;}  &lt;p&gt;现在我们的视频显示出来了！ &lt;p&gt;让我们再花一点时间来看一下SDL的特性：它的事件驱动系统。SDL被设置成当你在SDL中点击或者移动鼠标或者向它发送一个信号它都将产生一个事件的驱动方式。如果你的程序想要处理用户输入的话，它就会检测这些事件。你的程序也可以产生事件并且传递给SDL事件系统。当使用SDL进行多线程编程的时候，这相当有用，这方面代码我们可以在指导4中看到。在这个程序中，我们将在处理完包以后就立即轮询事件。现在而言，我们将处理SDL_QUIT事件以便于我们退出： &lt;p&gt;SDL_Event event; &lt;p&gt;av_free_packet(&amp;amp;packet); &lt;p&gt;SDL_PollEvent(&amp;amp;event); &lt;p&gt;switch(event.type) { &lt;p&gt;case SDL_QUIT: &lt;p&gt;SDL_Quit(); &lt;p&gt;exit(0); &lt;p&gt;break; &lt;p&gt;default: &lt;p&gt;break; &lt;p&gt;}  &lt;p&gt;让我们去掉旧的冗余代码，开始编译。如果你使用的是Linux或者其变体，使用SDL库进行编译的最好方式为： &lt;p&gt;gcc -o tutorial02 tutorial02.c -lavutil -lavformat -lavcodec -lz -lm \ &lt;p&gt;`sdl-config –cflags –libs`  &lt;p&gt;这里的sdl-config命令会打印出用于gcc编译的包含正确SDL库的适当参数。为了进行编译，在你自己的平台你可能需要做的有点不同：请查阅一下SDL文档中关于你的系统的那部分。一旦可以编译，就马上运行它。 &lt;p&gt;当运行这个程序的时候会发生什么呢？电影简直跑疯了！实际上，我们只是以我们能从文件中解码帧的最快速度显示了所有的电影的帧。现在我们没有任何代码来计算出我们什么时候需要显示电影的帧。最后（在指导5），我们将花足够的时间来探讨同步问题。但一开始我们会先忽略这个，因为我们有更加重要的事情要处理：音频！&lt;/p&gt;&lt;img src="http://www.cnblogs.com/jessezhao/aggbug/1755254.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/jessezhao/archive/2010/06/10/1755254.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry></feed>
