﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-CY's Java</title><link>http://www.blogjava.net/chenying19890808/</link><description>&lt;span style="color: red"&gt;&lt;span style="font-family: 幼圆"&gt;&lt;span style="color: red; font-family: "&gt;自己选择的路，摸爬滚打也要走下去&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 06:06:44 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 06:06:44 GMT</pubDate><ttl>60</ttl><item><title>IOS开发笔记 多个tableView的使用</title><link>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417150.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Wed, 20 Aug 2014 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417150.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/417150.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417150.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/417150.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/417150.html</trackback:ping><description><![CDATA[<h2><strong>UITableView是app开发中常用到的控件，功能很强大，多用于数据的显示。下面以一个简单的实例来介绍tableview的基本用法。（适合新手，高手飘过）</strong></h2><div><strong><img src="http://img.blog.csdn.net/20130614152745250" alt="" data-pinit="registered" style="border: none; max-width: 100%;" /><br /></strong></div><div><strong><br /></strong></div><div><strong></strong><div bg_cpp"="" style="width: 936.53125px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 469px; top: 901px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">@interface&nbsp;TableViewTestViewController&nbsp;:&nbsp;UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UITableView&nbsp;*DataTable;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray1;&nbsp;／／定义数据数组1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray2;／／定义数据数组2&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*titleArray;／／定义标题数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(void)viewDidLoad&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[superviewDidLoad];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">／／初始化tableview&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;=&nbsp;[[UITableViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;420)];／／指定位置大小&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDelegate:self];／／指定委托&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDataSource:self];／／指定数据委托&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self.viewaddSubview:DataTable];／／加载tableview&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray1&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"中国",&nbsp;@"美国",&nbsp;@"英国",&nbsp;nil];／／初始化数据数组1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray2&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"黄种人",&nbsp;@"黑种人",&nbsp;@"白种人",&nbsp;nil];／／初始化数据数组2&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;titleArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"国家",&nbsp;@"种族",&nbsp;nil];／／初始化标题数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(<span style="color: #2e8b57; font-weight: bold;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Return&nbsp;YES&nbsp;for&nbsp;supported&nbsp;orientations&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(interfaceOrientation&nbsp;==&nbsp;UIInterfaceOrientationPortrait);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//每个section显示的标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSString&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;titleForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;objectAtIndex:section];／／提取标题数组的元素用来显示标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;objectAtIndex:section];／／提取标题数组的元素用来显示标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;@"Unknown";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定有多少个分区(Section)，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)numberOfSectionsInTableView:(UITableView&nbsp;*)tableView&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;count];//返回标题数组中元素的个数来确定分区的个数&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定每个分区中有多少行，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)tableView:(UITableView&nbsp;*)tableView&nbsp;numberOfRowsInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray1&nbsp;count];／／每个分区通常对应不同的数组，返回其元素个数来确定分区的行数&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray2&nbsp;count];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//绘制Cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-(UITableViewCell&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;cellForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;NSString&nbsp;*CellIdentifier&nbsp;=&nbsp;@"Cell";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／初始化cell并指定其类型，也可自定义cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">UITableViewCell&nbsp;*cell&nbsp;=&nbsp;(UITableViewCell*)[tableView&nbsp;&nbsp;dequeueReusableCellWithIdentifier:CellIdentifier];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　if(cell&nbsp;==&nbsp;nil)&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　cell&nbsp;=&nbsp;[[[UITableViewCellalloc]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　initWithFrame:CGRectZero&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　reuseIdentifier:CellIdentifier]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;　　switch&nbsp;(indexPath.section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　case&nbsp;0:／／对应各自的分区&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:[dataArray1&nbsp;objectAtIndex:indexPath.row]];／／给cell添加数据&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:[dataArray2&nbsp;objectAtIndex:indexPath.row]];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:@"Unknown"];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　return&nbsp;cell;／／返回cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><br /><h2><strong>上面的例子在功能上介绍了tableview的使用，但其在数据处理上具有很大的局限性。当我们要从服务器上请求数据，面对多种可能的数据（主要指数组的个数不稳定）此时上面的switch将无法满足我们的需求了。使用switch可是代码的结构清晰明了，但其局限性很致命（switch中case的个数无法动态指定），下面的另一种方法可解决上述问题。</strong></h2></div><div><strong><img src="http://img.blog.csdn.net/20130614153129468" alt="" data-pinit="registered" style="border: none; max-width: 100%;" /><br /></strong></div><div><strong><br /></strong></div><h2><a name="t2" style="color: rgb(202, 0, 0);"></a><strong><span style="color: #ff0000;">代码在原由基础上进行的修改：</span></strong></h2><div><strong style="font-family: Arial; line-height: 26px;"></strong><div bg_cpp"="" style="width: 936.53125px; line-height: 26px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 469px; top: 4612px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">@interface&nbsp;TableViewTestViewController&nbsp;:&nbsp;UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UITableView&nbsp;*DataTable;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray1;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray2;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*titleArray;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray;&nbsp;／／加入了用于保存数组的数组&nbsp;dataArray&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(void)viewDidLoad&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[superviewDidLoad];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;=&nbsp;[[UITableViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;420)];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDelegate:self];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDataSource:self];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self.viewaddSubview:DataTable];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray1&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"中国",&nbsp;@"美国",&nbsp;@"英国",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray2&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"黄种人",&nbsp;@"黑种人",&nbsp;@"白种人",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;titleArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"国家",&nbsp;@"种族",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:dataArray1,&nbsp;dataArray2,&nbsp;nil];&nbsp;／／初始化dataArray，元素为数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(<span style="color: #2e8b57; font-weight: bold;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Return&nbsp;YES&nbsp;for&nbsp;supported&nbsp;orientations&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(interfaceOrientation&nbsp;==&nbsp;UIInterfaceOrientationPortrait);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／制定个性标题，这里通过UIview来设计标题，功能上丰富，变化多。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(UIView&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;viewForHeaderInSection:(NSInteger)section&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UIView&nbsp;*view&nbsp;=&nbsp;[[[UIViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;40)]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[view&nbsp;setBackgroundColor:[UIColorbrownColor]];／／改变标题的颜色，也可用图片&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UILabel&nbsp;*label&nbsp;=&nbsp;[[UILabelalloc]&nbsp;initWithFrame:CGRectMake(5,&nbsp;5,&nbsp;100,&nbsp;30)];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.textColor&nbsp;=&nbsp;[UIColorredColor];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.backgroundColor&nbsp;=&nbsp;[UIColorclearColor];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.text&nbsp;=&nbsp;[titleArrayobjectAtIndex:section];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[view&nbsp;addSubview:label];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;view;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／指定标题的高度&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(CGFloat)tableView:(UITableView&nbsp;*)tableView&nbsp;heightForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;40;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//每个section显示的标题，有了上面的这个就不要了&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSString&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;titleForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定有多少个分区(Section)，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)numberOfSectionsInTableView:(UITableView&nbsp;*)tableView&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArraycount];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定每个分区中有多少行，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)tableView:(UITableView&nbsp;*)tableView&nbsp;numberOfRowsInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;/*&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray1&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray2&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;/*&nbsp;&nbsp;for(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;[titleArray&nbsp;count];&nbsp;i++){&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(section&nbsp;==&nbsp;i){&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[[dataArray&nbsp;objectAtIndex:section]&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　／／上面的方法也是可行的，大家参考比较下&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[[dataArray&nbsp;objectAtIndex:section]&nbsp;count];&nbsp;&nbsp;／／取dataArray中的元素，并根据每个元素（数组）来判断分区中的行数。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//绘制Cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-(UITableViewCell&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;cellForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;NSString&nbsp;*CellIdentifier&nbsp;=&nbsp;@"Cell";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">UITableViewCell&nbsp;*cell&nbsp;=&nbsp;(UITableViewCell*)[tableView&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dequeueReusableCellWithIdentifier:CellIdentifier];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">if(cell&nbsp;==&nbsp;nil)&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">cell&nbsp;=&nbsp;[[[UITableViewCellalloc]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">initWithFrame:CGRectZero&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">reuseIdentifier:CellIdentifier]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">/*switch&nbsp;(indexPath.section)&nbsp;{&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">case&nbsp;0:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:[dataArray1&nbsp;objectAtIndex:indexPath.row]];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">case&nbsp;1:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:[dataArray2&nbsp;objectAtIndex:indexPath.row]];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">default:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:@"Unknown"];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;／／上面的方法也可行，大家比较下。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[[cell&nbsp;textLabel]&nbsp;setText:[[dataArrayobjectAtIndex:indexPath.section]objectAtIndex:indexPath.row]];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／同上，取出dataArray中每个分区所对应的元素（数组），并通过其来取值。&nbsp;（大家要有想像力，&nbsp;复制代码试试就明白了）&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">return&nbsp;cell;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;//改变行的高度&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(CGFloat)tableView:(UITableView&nbsp;*)tableView&nbsp;heightForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return40;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><div style="font-family: Arial; line-height: 26px;"><strong><br /></strong></div><h2><a name="t3" style="color: rgb(202, 0, 0);"></a><strong>转自：http://www.cnblogs.com/top5/archive/2012/05/17/2506604.html</strong></h2><div><strong><br /></strong></div><strong style="font-family: Arial; line-height: 26px;"></strong></div><script charset="utf-8"> (function(w, d, g, J) { var e = J.stringify || J.encode; d[g] = d[g] || {}; d[g]['showValidImages'] = d[g]['showValidImages'] || function() { w.postMessage(e({'msg': {'g': g, 'm':'s'}}), location.href); } })(window, document, '__huaban', JSON); </script><img src ="http://www.blogjava.net/chenying19890808/aggbug/417150.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2014-08-20 10:44 <a href="http://www.blogjava.net/chenying19890808/archive/2014/08/20/417150.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS开发笔记 多个tableView的使用</title><link>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417151.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Wed, 20 Aug 2014 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417151.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/417151.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2014/08/20/417151.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/417151.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/417151.html</trackback:ping><description><![CDATA[<h2><strong>UITableView是app开发中常用到的控件，功能很强大，多用于数据的显示。下面以一个简单的实例来介绍tableview的基本用法。（适合新手，高手飘过）</strong></h2><div><strong><img src="http://img.blog.csdn.net/20130614152745250" alt="" data-pinit="registered" style="border: none; max-width: 100%;" /><br /></strong></div><div><strong><br /></strong></div><div><strong></strong><div bg_cpp"="" style="width: 936.53125px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 469px; top: 901px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">@interface&nbsp;TableViewTestViewController&nbsp;:&nbsp;UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UITableView&nbsp;*DataTable;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray1;&nbsp;／／定义数据数组1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray2;／／定义数据数组2&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*titleArray;／／定义标题数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(void)viewDidLoad&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[superviewDidLoad];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">／／初始化tableview&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;=&nbsp;[[UITableViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;420)];／／指定位置大小&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDelegate:self];／／指定委托&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDataSource:self];／／指定数据委托&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self.viewaddSubview:DataTable];／／加载tableview&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray1&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"中国",&nbsp;@"美国",&nbsp;@"英国",&nbsp;nil];／／初始化数据数组1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray2&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"黄种人",&nbsp;@"黑种人",&nbsp;@"白种人",&nbsp;nil];／／初始化数据数组2&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;titleArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"国家",&nbsp;@"种族",&nbsp;nil];／／初始化标题数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(<span style="color: #2e8b57; font-weight: bold;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Return&nbsp;YES&nbsp;for&nbsp;supported&nbsp;orientations&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(interfaceOrientation&nbsp;==&nbsp;UIInterfaceOrientationPortrait);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//每个section显示的标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSString&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;titleForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;objectAtIndex:section];／／提取标题数组的元素用来显示标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;objectAtIndex:section];／／提取标题数组的元素用来显示标题&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;@"Unknown";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定有多少个分区(Section)，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)numberOfSectionsInTableView:(UITableView&nbsp;*)tableView&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArray&nbsp;count];//返回标题数组中元素的个数来确定分区的个数&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定每个分区中有多少行，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)tableView:(UITableView&nbsp;*)tableView&nbsp;numberOfRowsInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray1&nbsp;count];／／每个分区通常对应不同的数组，返回其元素个数来确定分区的行数&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray2&nbsp;count];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//绘制Cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-(UITableViewCell&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;cellForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;NSString&nbsp;*CellIdentifier&nbsp;=&nbsp;@"Cell";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／初始化cell并指定其类型，也可自定义cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">UITableViewCell&nbsp;*cell&nbsp;=&nbsp;(UITableViewCell*)[tableView&nbsp;&nbsp;dequeueReusableCellWithIdentifier:CellIdentifier];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　if(cell&nbsp;==&nbsp;nil)&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　cell&nbsp;=&nbsp;[[[UITableViewCellalloc]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　initWithFrame:CGRectZero&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　reuseIdentifier:CellIdentifier]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;　　switch&nbsp;(indexPath.section)&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　case&nbsp;0:／／对应各自的分区&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:[dataArray1&nbsp;objectAtIndex:indexPath.row]];／／给cell添加数据&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　case&nbsp;1:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:[dataArray2&nbsp;objectAtIndex:indexPath.row]];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　break;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　default:&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　　　[[cell&nbsp;textLabel]&nbsp;&nbsp;setText:@"Unknown"];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　return&nbsp;cell;／／返回cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><br /><h2><strong>上面的例子在功能上介绍了tableview的使用，但其在数据处理上具有很大的局限性。当我们要从服务器上请求数据，面对多种可能的数据（主要指数组的个数不稳定）此时上面的switch将无法满足我们的需求了。使用switch可是代码的结构清晰明了，但其局限性很致命（switch中case的个数无法动态指定），下面的另一种方法可解决上述问题。</strong></h2></div><div><strong><img src="http://img.blog.csdn.net/20130614153129468" alt="" data-pinit="registered" style="border: none; max-width: 100%;" /><br /></strong></div><div><strong><br /></strong></div><h2><a name="t2" style="color: rgb(202, 0, 0);"></a><strong><span style="color: #ff0000;">代码在原由基础上进行的修改：</span></strong></h2><div><strong style="font-family: Arial; line-height: 26px;"></strong><div bg_cpp"="" style="width: 936.53125px; line-height: 26px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/hopedark/article/details/9095203#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 469px; top: 4612px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">@interface&nbsp;TableViewTestViewController&nbsp;:&nbsp;UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UITableView&nbsp;*DataTable;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray1;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray2;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*titleArray;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSMutableArray&nbsp;*dataArray;&nbsp;／／加入了用于保存数组的数组&nbsp;dataArray&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(void)viewDidLoad&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[superviewDidLoad];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;=&nbsp;[[UITableViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;420)];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDelegate:self];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[DataTablesetDataSource:self];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self.viewaddSubview:DataTable];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray1&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"中国",&nbsp;@"美国",&nbsp;@"英国",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray2&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"黄种人",&nbsp;@"黑种人",&nbsp;@"白种人",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;titleArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:@"国家",&nbsp;@"种族",&nbsp;nil];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;dataArray&nbsp;=&nbsp;[[NSMutableArrayalloc]&nbsp;initWithObjects:dataArray1,&nbsp;dataArray2,&nbsp;nil];&nbsp;／／初始化dataArray，元素为数组&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(<span style="color: #2e8b57; font-weight: bold;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Return&nbsp;YES&nbsp;for&nbsp;supported&nbsp;orientations&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(interfaceOrientation&nbsp;==&nbsp;UIInterfaceOrientationPortrait);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／制定个性标题，这里通过UIview来设计标题，功能上丰富，变化多。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(UIView&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;viewForHeaderInSection:(NSInteger)section&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UIView&nbsp;*view&nbsp;=&nbsp;[[[UIViewalloc]&nbsp;initWithFrame:CGRectMake(0,&nbsp;0,&nbsp;320,&nbsp;40)]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[view&nbsp;setBackgroundColor:[UIColorbrownColor]];／／改变标题的颜色，也可用图片&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UILabel&nbsp;*label&nbsp;=&nbsp;[[UILabelalloc]&nbsp;initWithFrame:CGRectMake(5,&nbsp;5,&nbsp;100,&nbsp;30)];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.textColor&nbsp;=&nbsp;[UIColorredColor];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.backgroundColor&nbsp;=&nbsp;[UIColorclearColor];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;label.text&nbsp;=&nbsp;[titleArrayobjectAtIndex:section];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[view&nbsp;addSubview:label];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;view;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／指定标题的高度&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(CGFloat)tableView:(UITableView&nbsp;*)tableView&nbsp;heightForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;40;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//每个section显示的标题，有了上面的这个就不要了&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSString&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;titleForHeaderInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定有多少个分区(Section)，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)numberOfSectionsInTableView:(UITableView&nbsp;*)tableView&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[titleArraycount];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//指定每个分区中有多少行，默认为1&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(NSInteger)tableView:(UITableView&nbsp;*)tableView&nbsp;numberOfRowsInSection:(NSInteger)section{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;/*&nbsp;switch&nbsp;(section)&nbsp;{&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;0:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray1&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;1:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&nbsp;[dataArray2&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;/*&nbsp;&nbsp;for(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;[titleArray&nbsp;count];&nbsp;i++){&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(section&nbsp;==&nbsp;i){&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[[dataArray&nbsp;objectAtIndex:section]&nbsp;count];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">　　／／上面的方法也是可行的，大家参考比较下&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[[dataArray&nbsp;objectAtIndex:section]&nbsp;count];&nbsp;&nbsp;／／取dataArray中的元素，并根据每个元素（数组）来判断分区中的行数。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">//绘制Cell&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-(UITableViewCell&nbsp;*)tableView:(UITableView&nbsp;*)tableView&nbsp;cellForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;NSString&nbsp;*CellIdentifier&nbsp;=&nbsp;@"Cell";&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">UITableViewCell&nbsp;*cell&nbsp;=&nbsp;(UITableViewCell*)[tableView&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dequeueReusableCellWithIdentifier:CellIdentifier];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">if(cell&nbsp;==&nbsp;nil)&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">cell&nbsp;=&nbsp;[[[UITableViewCellalloc]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">initWithFrame:CGRectZero&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">reuseIdentifier:CellIdentifier]&nbsp;autorelease];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">/*switch&nbsp;(indexPath.section)&nbsp;{&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">case&nbsp;0:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:[dataArray1&nbsp;objectAtIndex:indexPath.row]];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">case&nbsp;1:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:[dataArray2&nbsp;objectAtIndex:indexPath.row]];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">break;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">default:&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">[[cell&nbsp;textLabel]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">setText:@"Unknown"];&nbsp;</li><li style="line-height: 18px;">&nbsp;</li><li style="line-height: 18px;">}*/&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;／／上面的方法也可行，大家比较下。&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[[cell&nbsp;textLabel]&nbsp;setText:[[dataArrayobjectAtIndex:indexPath.section]objectAtIndex:indexPath.row]];&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;／／同上，取出dataArray中每个分区所对应的元素（数组），并通过其来取值。&nbsp;（大家要有想像力，&nbsp;复制代码试试就明白了）&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">return&nbsp;cell;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;//改变行的高度&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">-&nbsp;(CGFloat)tableView:(UITableView&nbsp;*)tableView&nbsp;heightForRowAtIndexPath:(NSIndexPath&nbsp;*)indexPath{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;return40;&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><div style="font-family: Arial; line-height: 26px;"><strong><br /></strong></div><h2><a name="t3" style="color: rgb(202, 0, 0);"></a><strong>转自：http://www.cnblogs.com/top5/archive/2012/05/17/2506604.html</strong></h2><div><strong><br /></strong></div><strong style="font-family: Arial; line-height: 26px;"></strong></div><script charset="utf-8"> (function(w, d, g, J) { var e = J.stringify || J.encode; d[g] = d[g] || {}; d[g]['showValidImages'] = d[g]['showValidImages'] || function() { w.postMessage(e({'msg': {'g': g, 'm':'s'}}), location.href); } })(window, document, '__huaban', JSON); </script><img src ="http://www.blogjava.net/chenying19890808/aggbug/417151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2014-08-20 10:44 <a href="http://www.blogjava.net/chenying19890808/archive/2014/08/20/417151.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>三十而立，从零开始学ios开发（十）：Multiview Applications（多个xib之前的切换） </title><link>http://www.blogjava.net/chenying19890808/archive/2014/06/27/415167.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Fri, 27 Jun 2014 02:04:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2014/06/27/415167.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/415167.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2014/06/27/415167.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/415167.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/415167.html</trackback:ping><description><![CDATA[<p>这篇学习的主要内容是Multiview，在我们学习iphone旋转的时候，介绍过多个view的使用方法，不过这里的view和旋转屏幕中所指的多个view是不同的，旋转屏幕中涉及到的多个view是在一个xib文件中的，而我们这里所指的mulitview，则是指多个xib，在多个xib中进行view的切换，也就是从一个xib切换到另一个xib，而每个xib中只有一个view。</p><p>另外的一个不同点体现在创建项目的时候，到目前为止，我们创建的所有项目的template都是single view，这次创建的项目将使用新的template。</p><p>Multiview applicatin的基本架构，一般来说，一个multiview application会有一个主要的controller来控制view的呈现，这个主要的controller可以是toolbar（iphone上的Safari打开后，地下的一排按钮就是toolbar）或者是tab bar（iphone打开phone，最下面一个一个的tab），或者其他的一些控件，他们控制到底那个view应该显示，那个view应该被隐藏，也就是说，至少需要3个view才能实现view的切换，一个主要的controller view，2个其他的用于切换的view，主要的controller view是一直显示在屏幕上的，而其他的view中，只有1个会显示出来，其他的都被隐藏。ok，下面开始一步一步实现multiview吧，再说下去会越来越糊涂的。</p><p>0）项目简介<br />今天要做的例子中包含3个view，一个controller view，我们会使用toolbar，2个用于切换的view，一个蓝色底，一个黄色底，他们中间都有一个button，单击button会有一个警告框弹出，告诉用户当前显示的是哪个view。</p><p>1）创建一个工程，选择Empty Application<br /><img style="width: 658px;" alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120823242639.png" data-pinit="registered" /><br />这次<strong>不再</strong>选择Single View Application，而选择<strong>Empty Application</strong>，项目中的所有文件我们都会手动进行添加。</p><p>单击Next按钮，之后的操作和创建Single View项目一样，设定项目名称&#8220;View Switcher&#8221;，设定项目保存路径，项目创建完成。</p><p>2）添加View Controller<br />由于我们使用的模板是Empty Application，因此当创建完项目后，只有以下一些文件<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120823595384.png" data-pinit="registered" /><br />里面并没有我们需要的controller view，也没有任何xib文件，这些都是需要我们手动添加的。使用快捷键command+N或者菜单栏File&gt;New&gt;New File...，在弹出的窗口中，左边选择Cocoa Touch，右边选择UIViewController subclass，点击Next按钮<br /><img style="width: 658px;" alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900050368.png" data-pinit="registered" /></p><p>填写类名BIDSwitchViewController，其他都是默认选项（注意最后一个checkbox，如果选择了，则将创建一个和BIDSwitchViewController关联的xib文件，我们在这里可以选上，但是为了弄清楚view controller和xib文件是如何关联在一起的，在这个项目中我们暂时不选，后面我们会手动连接这两个文件），点击Next按钮。<br /><img style="width: 658px;" alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900082053.png" data-pinit="registered" /><br />选择保持的位置，保存在&#8220;View Switcher&#8221;目录下，完成创建。</p><p>BIDSwitchViewController是项目的最顶层的view controller（root controller），它用于控制另外2个view的切换，下面按照同样的方法，创建另外2个view controller，一个名字教BIDBlueViewController，另一个叫做BIDYellowViewController，他们都不需要关联xib，且都保存在&#8220;View Switcher&#8221;目录下。创建完成后的&#8220;View Switcher&#8221;结构如下<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900211063.png" data-pinit="registered" /></p><p>3）添加xib文件<br />使用快捷键command+N或者菜单栏File&gt;New&gt;New File...，在弹出的窗口中，左边选择User Interface，右边选择View，点击Next按钮<br /><img style="width: 658px;" alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900402725.png" data-pinit="registered" /></p><p>Device Family中选择iphone，点击Next</p><p>命名为SwitchView.xib，同样保持在&#8220;View Switcher&#8221;目录下，点击Create，完成创建。<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900491026.png" data-pinit="registered" /><br />使用同样的方法创建另外两个xib，分别命名为BlueView.xib和YellowView.xib。至此，我们所有的文件都已经创建完毕，整个的&#8220;View Switcher&#8221;结构图如下<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120900515976.png" data-pinit="registered" /><br />接下来就是写代码的工作了。</p><p>4）编辑BIDAppDelegate文件<br />当一个app启动的时候，我们都会默认的把一个view载入当前的iphone窗口（application's main window），在这个例子中，这个view就是我们的root view，即BIDSwitchViewController。我们是在BIDAppDelegate文件中设置默认载入的view的，因此首先打开BIDAppDelegate.h，添加class BIDSwitchViewController，和它的一个property，如下</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>#import &lt;UIKit/UIKit.h&gt; <strong>@class BIDSwitchViewController; </strong>@interface BIDAppDelegate : UIResponder &lt;UIApplicationDelegate&gt;  @property (strong, nonatomic) UIWindow *window; <strong>@property (strong, nonatomic) BIDSwitchViewController </strong><strong>*switchViewController;  </strong>@end</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>其中，@class是告诉BIDAppDelegate，后面的BIDSwitchViewController是一个类，应该以类的方式处理该对象，后面在声明property的时候，BIDAppDelegate就知道BIDSwitchViewController是一个类，不会不认该对象。</p><p>接着打开BIDAppDelegate.m，添加如下代码</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>#import "BIDAppDelegate.h" <strong>#import "BIDSwitchViewController.h"</strong>  @implementation BIDAppDelegate  @synthesize window = _window; <strong>@synthesize switchViewController;  </strong>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];     // Override point for customization after application launch. <strong>         self.switchViewController = [[BIDSwitchViewController alloc] initWithNibName:@"SwitchView" bundle:nil];     UIView *switchView = self.switchViewController.view;     CGRect switchViewFrame = switchView.frame;     switchViewFrame.origin.y += [UIApplication sharedApplication].statusBarFrame.size.height;     switchView.frame =</strong><strong> switchViewFrame;     [self.window addSubview:switchView];</strong>          self.window.backgroundColor = [UIColor whiteColor];     [self.window makeKeyAndVisible];     return YES; }  ......</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>首先import BIDSwitchViewController，然后声明synthesize，对应于头文件中的property。</p><p>didFinishLaunchingWithOption方法，当一个app载入完成后需要做一些什么事情，在这里，我们指定了哪个view被载入到windows中作为默认显示的view。</p><p>self.switchViewController = [[BIDSwitchViewControlleralloc] initWithNibName:@"SwitchView"&nbsp;bundle:nil];<br />通过xib（在旧的版本中，xib被称为nib，因此这里出现的是NibName）的名字来制定初始化哪个view</p><p>UIView *switchView = self.switchViewController.view;<br />获取view</p><p>CGRect switchViewFrame = switchView.frame;<br />得到view的frame，也就是这个view的显示位置，在前几篇的文章中提到过这个属性。</p><p>switchViewFrame.origin.y += [UIApplicationsharedApplication].statusBarFrame.size.height;<br />我觉得这句话比较重要，它将view的位置往下移动了20point（point在非retina屏幕中是20px，在retina屏幕中是40px），这样就不会挡住iphone顶部的状态栏了。</p><p>switchView.frame = switchViewFrame;<br />将修改过的frame从新赋值给switchView</p><p>[self.window addSubview:switchView];<br />将switchView设置成window的subview。怎么理解这句话呢，就是说，一个app只有一个窗口（window），这个window只能同时显示一个view，且这个view是基于这个window而存在的，是放在这个window里面的，因此称之为window的subview，子视图。</p><p>5）编辑BIDSwitchViewController.h<br />BIDSwitchViewController是root controller，用于控制其他2个view的切换，因此需要在其头文件中声明其他两个controller，然后需要定义一个Action，用来完成对2个view的切换，将BIDSwitchViewController.h修改成如下</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>#import &lt;UIKit/UIKit.h&gt;  <strong>@class BIDBlueViewController; @class BIDYellowViewController;</strong>  @interface BIDSwitchViewController : UIViewController  <strong>@property (strong, nonatomic) BIDBlueViewController *blueViewController; @property (strong, nonatomic) BIDYellowViewController *yellowViewController;</strong>  - (IBAction)switchViews:(id)sender;  @end</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>代码还是很好理解的，和前面在BIDAppDelegate.h中添加BIDSwitchViewController是一样的。</p><p>6）关联BIDSwitchViewController和SwitchView.xib<br />在Project Navigator中选中SwitchView.xib，在xib的dock中选中File's Owner<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923082088.png" data-pinit="registered" /></p><p>然后在Identity inspector中将Class改成BIDSwitchViewController<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923113591.png" data-pinit="registered" /><br />这样就将SwitchView.xib关联到了BIDSwitchViewController，如果我们选择Connections inspector，会看到我们刚才在BIDSwitchViewController.h中定义的Action：switchViews出现在Received Actions，我们之后就可以将这个Action关联到SwitchView.xib的控件上。</p><p>7）在SwitchView.xib上添加Toolbar<br />在这个例子总，我们切换veiw的方式是点击Toolbar上的一个button，然后切换2个view，SwitchView.xib使我们的root view，因此我们需要在SwitchView.xib上添加一个toolbar，然后点击toolbar上的按钮，切换BlueView.xib和YellowView.xib。</p><p>选中SwitchView.xib，在object library中找到Toolbar<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923290034.png" /><br />拖动到View上，放在最下方<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923300438.png" data-pinit="registered" /><br />默认的，已经有一个button在Toolbar上了，双击button改变文字，将文字改成&#8220;Switch Views&#8221;<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923321662.png" /><br />接着就是将&#8220;Switch Views&#8221;按钮关联到switchViews，选中&#8220;Switch Views&#8221;，control-dragged到File's Owner，在弹出的框中选中switchViews<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923413640.png" /><br />打开Connections inspector，我们可以看到关联后的情况<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012120923433150.png" data-pinit="registered" /><br />有一个不同的地方，Toolbar上的button不像一般的button，会有很多的方法让你进行关联，Toolbar上button的Sent Actions（其他的button叫做Send Events，有很多个方法）只有一个方法，而它的作用相当于一般button的touch up inside。</p><p>8）关联SwitchView.xib和BIDSwitchViewController's view outlet<br />BIDSwitchViewController继承自UIViewController，在UIViewController中有一个outlet view，另外当我们在做第6）步的时候，将SwitchView.xib的class改成了BIDSwitchViewController，所以我们要将这个view关联到SwitchView.xib，关联的方法是选中SwitchView.xib，然后选中File's Owner，control-drag到下面的View<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121022245527.png" data-pinit="registered" /><br />释放鼠标后，在填出的框中选则view，这样就关联好了。<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121022273227.png" data-pinit="registered" /><br />关联好后，查看Connections inspector，也可以看到关联后的结果<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121022281732.png" /></p><p>9）编辑BIDSwitchViewController.m<br />添加如下代码</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>#import "BIDSwitchViewController.h" <strong>#import "BIDYellowViewController.h" #import "BIDBlueViewController.h" </strong> @implementation BIDSwitchViewController <strong>@synthesize yellowViewController; @synthesize blueViewController;</strong></pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>2个#import这个很好理解，因为BIDSwitchViewController是root controller，会控制另外2个controller，因此需要把另外2个controller引入进来，这样才可以对他们进行操作。<br />2个synthesize对着头文件中的2个property。</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad {     <strong>self.blueViewController </strong><strong>= [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];     [self.view insertSubview:self.blueViewController.view atIndex:0</strong><strong>];</strong>     [super viewDidLoad]; }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>首先去掉viewDidLoad的注释，然后添加以上的代码。从最后一句可以看出，viewDidLoad方法继承自UIViewController，在这里对其重载，这个方法发生在当view已经载入完成后，我们所要做的是当root view载入完成后，在载入root view的subview，在我们的这个例子中是BlueView。BlueView的载入方法和前面的一样，使用initWithNibName，然后作为subView插入到当前的view中（当前的view就是root view，也就是SwitchView）。</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>- (IBAction)switchViews:(id)sender {     if(self.yellowViewController.view.superview == nil) {         if(self.yellowViewController == nil) {             self.yellowViewController = [[BIDYellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];         }         [blueViewController.view removeFromSuperview];         [self.view insertSubview:self.yellowViewController.view atIndex:0];     } else {         if (self.blueViewController ==nil) {             self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];         }         [yellowViewController.view removeFromSuperview];         [self.view insertSubview:self.blueViewController.view atIndex:0];     } }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>实现switchViews Action，上面的代码还是很好理解的，首先判断当前哪个subview是没有superview的，因为这2个subview不会同时显示，当blueSubview显示时，YellowSubview就会从root view中移除，因此不会具有superview，当得知那个subview没有superview，就说明应该显示这个subview。知道该显示哪个subview后，再判断这个subview是否还存在（是否需要重新载入初始化），然后将另一个subview从superview中移除，再将subview显示出来。</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>- (void)didReceiveMemoryWarning {     // Releases the view if it doesn't have a superview.     [super didReceiveMemoryWarning];          // Release any cached data, images, etc that aren't in use.     <strong>if (self.blueViewController.view.superview == nil){         self.blueViewController = nil;     } else {         self.yellowViewController =</strong><strong> nil;     }</strong> }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>当ios的内存不够用时，didReceiveMemoryWarning会被系统自动调用，来释放可利用的内存。在这里如果哪个subview没有显示，就释放该subview，腾出内存。</p><p>至此BIDSwitchViewController的所有代码都写好了，下面就应该处理BIDBlueVeiwController和BIDYellowViewController了。</p><p>（友情提示，时不时的编译一下你的project，尽早发现问题，容易修改，否则到后面自己都不知道错在哪里）</p><p>10）编辑BlueView.xib和YellowView.xib<br />分别在BlueView.xib和YellowView.xib上添加一个button，并命名为&#8220;Press me&#8221;。<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121023261536.png" data-pinit="registered" /></p><p>修改BlueView.xib的class为BIDBlueViewController，修改YellowView.xib的class为BIDYellowController（修改方法：选中xib，点击File's Owner，在Identity inspector中更改class）<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121023340129.png" />&nbsp;<img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121023341535.png" /><br />class改变了，就需要重新关联一下File's owner的view，方法和之前的一样，选中File&#8216;s Owner，control-drag到下面的View上，在弹出的框中选择view，关联完毕，2个xib都需要进行这个操作。</p><p>在Attributes inspector中，将BlueView.xib的background颜色改成蓝色<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121023390597.png" data-pinit="registered" /><br />同样的方法将YellowView.xib的background颜色改成黄色<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121023403112.png" data-pinit="registered" /></p><p>还有一个地方需要设置，因为我们是在root view中显示这2个subview，而root view有一个toolbar在最下方，因此subview需要把toolbar的位置空出来，再进行自己的布局，还是打开Attributes inspector，在Simulated Metrics栏中有很多现象，他们都是用来模拟iphone屏幕上各种占位控件的，我们将Button Bar的选项设成Toolbar，这样xib就会空出Toolbar的位置来进行布局计算了<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121100305217.png" data-pinit="registered" /><br />仔细看的话，&#8220;Press me&#8221;按钮的位置往上移动了那么一点点</p><p>11）在BIDBlueViewController和BIDYellowViewController中添加代码<br />在BIDBlueViewController.h中添加Action，如下</p><div><pre>@interface BIDBlueViewController : UIViewController <strong>- (IBAction)blueButtonPressed; </strong>@end</pre></div><p>在BIDBlueViewController.m中实现blueButtonPressed，如下</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>- (IBAction)blueButtonPressed {     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blue View Button Pressed"                                                     message:@"You pressed the button on the blue view"                                                    delegate:nil                                           cancelButtonTitle:@"Yep, I did"                                           otherButtonTitles:nil];     [alert show]; }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>在BIDYellowViewController.h添加Action，如下</p><div><pre>@interface BIDYellowViewController : UIViewController <strong>- (IBAction)yellowButtonPressed; </strong>@end</pre></div><p>在BIDYellowViewController.m中实现yellowButtonPressed，如下</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>- (IBAction)yellowButtonPressed {     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yellow View Button Pressed"                                                     message:@"You pressed the button on the yellow view"                                                    delegate:nil                                           cancelButtonTitle:@"Yep, I did"                                           otherButtonTitles:nil];     [alert show]; }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>代码都很简单，就不多做解释了。</p><p>12）关联button和Action<br />打开BlueView.xib，选中&#8220;Press me&#8221;按钮，control-drag到File's owner释放，在填出的框中选择blueButtonPressed。<br />打开YellowView.xib，选中&#8220;Press me&#8221;按钮，control-drag到File's owner释放，在填出的框中选择yellowButtonPressed。</p><p>13）编译运行<br />至此我们已经可以编译运行程序了，编译成功后，iphone模拟器中显示的效果（&#8220;Press me&#8221;按钮的效果就不演示了）<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121100001546.png" data-pinit="registered" /></p><p>按下&#8220;Switch Views&#8221;按钮，BlueSubview会切换到YellowSubview<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121100015782.png" data-pinit="registered" /></p><p>14）更炫的切换view的方法<br />有没有发现上面切换view效果很无聊，ios中有更炫的切换view的方法，使用动画的方式切换view，打开BIDSwitchViewController.m，重新编辑switchViews方法，如下</p><div><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div><pre>- (IBAction)switchViews:(id)sender {         <strong>[UIView beginAnimations:</strong><strong>@"View Flip" context:nil];     [UIView setAnimationDuration:1.25];     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];          </strong>if(self.yellowViewController.view.superview == nil) {         if(self.yellowViewController == nil) {             self.yellowViewController = [[BIDYellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];         }         <strong>[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];</strong>         [blueViewController.view removeFromSuperview];         [self.view insertSubview:self.yellowViewController.view atIndex:0];     } else {         if (self.blueViewController ==nil) {             self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];         }         <strong>[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];</strong>         [yellowViewController.view removeFromSuperview];         [self.view insertSubview:self.blueViewController.view atIndex:0];     }     <strong>[UIView commitAnimations];</strong> }</pre><div><img alt="复制代码" src="http://common.cnblogs.com/images/copycode.gif" /></div></div><p>[UIViewbeginAnimations:@"View Flip"&nbsp;context:nil];<br />先可以不用理解这句话的意思，因为我也没有理解，反正这行代码是声明一个animation block，前一个参数是设置animation block的title，后一个参数是设置一个对象，我也搞不清楚是干什么的，大概在以后的学习中会有所了解。</p><p>[UIViewsetAnimationDuration:1.25];<br />设定动画时间，即切换view的时间</p><p>[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];<br />设定动画的运动方式，开始慢，中间快，最后慢，大家开始看ios自己的说明吧。（An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.）</p><p>[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view&nbsp;cache:YES];<br />设定切换的样式，一共有4个值可以选：<br />UIViewAnimationTransitionFlipFromRight<br />UIViewAnimationTransitionFlipFromLeft<br />UIViewAnimationTransitionFlipCurUp<br />UIViewAnimationTransitionFlipCurDown<br />这个大家自试试就可以知道了</p><p>[UIViewcommitAnimations];<br />当所有动画的值设置完毕后，提交动画，之后view就会按照设定的动画进行view的切换了。<br /><img alt="" src="http://pic002.cnblogs.com/images/2012/356178/2012121100223945.png" data-pinit="registered" /><br />（此图截于书本，因此不同清晰）</p><p>15）总结<br />ok，所有的功能都已经完成了，在这个例子中，我们使用toolbar来完成对不同view的切换，我们需要一个root view进行总的控制，然后多个subview进行切换，最后还使用一个比较炫的效果进行view之间的转换，内容很充实！<br /><br /></p><p><a href="http://files.cnblogs.com/minglz/View_Switcher.zip">View Switcher<br /><br />原文地址</a>：http://www.cnblogs.com/minglz/archive/2012/12/11/2809368.html</p><img src ="http://www.blogjava.net/chenying19890808/aggbug/415167.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2014-06-27 10:04 <a href="http://www.blogjava.net/chenying19890808/archive/2014/06/27/415167.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>常见Oracle HINT的用法</title><link>http://www.blogjava.net/chenying19890808/archive/2014/06/16/oracle_hint.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Mon, 16 Jun 2014 09:31:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2014/06/16/oracle_hint.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/414813.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2014/06/16/oracle_hint.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/414813.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/414813.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; line-height: 26px;">在SQL语句优化过程中，我们经常会用到hint,现总结一下在SQL优化过程中常见Oracle HINT的用法：</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">1. /*+ALL_ROWS*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">2. /*+FIRST_ROWS*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对语句块选择基于开销的优化方法,并获得最佳响应时间,使资源消耗最小化.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+FIRST_ROWS*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">3. /*+CHOOSE*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明如果数据字典中有访问表的统计信息,将基于开销的优化方法,并获得最佳的吞吐量;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明如果数据字典中没有访问表的统计信息,将基于规则开销的优化方法;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+CHOOSE*/ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">4. /*+RULE*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对语句块选择基于规则的优化方法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+ RULE */ EMP_NO,EMP_NAM,DAT_IN FROM BSEMPMS WHERE EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">5. /*+FULL(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对表选择全局扫描的方法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">6. /*+ROWID(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">提示明确表明对指定表根据ROWID进行访问.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+ROWID(BSEMPMS)*/ * FROM BSEMPMS WHERE ROWID&gt;='AAAAAAAAAAAAAA'</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">AND EMP_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">7. /*+CLUSTER(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">提示明确表明对指定表选择簇扫描的访问方法,它只对簇对象有效.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+CLUSTER */ BSEMPMS.EMP_NO,DPT_NO FROM BSEMPMS,BSDPTMS</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">WHERE DPT_NO='TEC304' AND BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">8. /*+INDEX(TABLE INDEX_NAME)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对表选择索引的扫描方法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX(BSEMPMS SEX_INDEX) USE SEX_INDEX BECAUSE THERE ARE FEWMALE BSEMPMS */ FROM BSEMPMS WHERE SEX='M';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">9. /*+INDEX_ASC(TABLE INDEX_NAME)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对表选择索引升序的扫描方法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ FROM BSEMPMS WHERE DPT_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">10. /*+INDEX_COMBINE*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">为指定表选择位图访问路经,如果INDEX_COMBINE中没有提供作为参数的索引,将选择出位图索引的布尔组合方式.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI)*/ * FROM BSEMPMS</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">WHERE SAL&lt;5000000 AND HIREDATE&lt;SYSDATE;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">11. /*+INDEX_JOIN(TABLE INDEX_NAME)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">提示明确命令优化器使用索引作为访问路径.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_JOIN(BSEMPMS SAL_HMI HIREDATE_BMI)*/ SAL,HIREDATE</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">FROM BSEMPMS WHERE SAL&lt;60000;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">12. /*+INDEX_DESC(TABLE INDEX_NAME)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">表明对表选择索引降序的扫描方法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_DESC(BSEMPMS PK_BSEMPMS) */ FROM BSEMPMS WHERE DPT_NO='SCOTT';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">13. /*+INDEX_FFS(TABLE INDEX_NAME)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">对指定的表执行快速全索引扫描,而不是全表扫描的办法.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_FFS(BSEMPMS IN_EMPNAM)*/ * FROM BSEMPMS WHERE DPT_NO='TEC305';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">14. /*+ADD_EQUAL TABLE INDEX_NAM1,INDEX_NAM2,...*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">提示明确进行执行规划的选择,将几个单列索引的扫描合起来.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+INDEX_FFS(BSEMPMS IN_DPTNO,IN_EMPNO,IN_SEX)*/ * FROM BSEMPMS WHERE EMP_NO='SCOTT' AND DPT_NO='TDC306';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">15. /*+USE_CONCAT*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">对查询中的WHERE后面的OR条件进行转换为UNION ALL的组合查询.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+USE_CONCAT*/ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">16. /*+NO_EXPAND*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">对于WHERE后面的OR 或者IN-LIST的查询语句,NO_EXPAND将阻止其基于优化器对其进行扩展.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+NO_EXPAND*/ * FROM BSEMPMS WHERE DPT_NO='TDC506' AND SEX='M';</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">17. /*+NOWRITE*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">禁止对查询块的查询重写操作.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">18. /*+REWRITE*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">可以将视图作为参数.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">19. /*+MERGE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">能够对视图的各个查询进行相应的合并.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELET DPT_NO</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">AND A.SAL&gt;V.AVG_SAL;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">20. /*+NO_MERGE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">对于有可合并的视图不再合并.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+NO_MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELECT DPT_NO,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO AND A.SAL&gt;V.AVG_SAL;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">21. /*+ORDERED*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">根据表出现在FROM中的顺序,ORDERED使ORACLE依此顺序对其连接.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+ORDERED*/ A.COL1,B.COL2,C.COL3 FROM TABLE1 A,TABLE2 B,TABLE3 C WHERE A.COL1=B.COL1 AND B.COL1=C.COL1;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">22. /*+USE_NL(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">将指定表与嵌套的连接的行源进行连接,并把指定表作为内部表.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+ORDERED USE_NL(BSEMPMS)*/ BSDPTMS.DPT_NO,BSEMPMS.EMP_NO,BSEMPMS.EMP_NAM FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">23. /*+USE_MERGE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">将指定的表与其他行源通过合并排序连接方式连接起来.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+USE_MERGE(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">24. /*+USE_HASH(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">将指定的表与其他行源通过哈希连接方式连接起来.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+USE_HASH(BSEMPMS,BSDPTMS)*/ * FROM BSEMPMS,BSDPTMS WHERE BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">25. /*+DRIVING_SITE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">强制与ORACLE所选择的位置不同的表进行查询执行.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+DRIVING_SITE(DEPT)*/ * FROM BSEMPMS,DEPT@BSDPTMS WHERE BSEMPMS.DPT_NO=DEPT.DPT_NO;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">26. /*+LEADING(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">将指定的表作为连接次序中的首表.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">27. /*+CACHE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">当进行全表扫描时,CACHE提示能够将表的检索块放置在缓冲区缓存中最近最少列表LRU的最近使用端</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+FULL(BSEMPMS) CAHE(BSEMPMS) */ EMP_NAM FROM BSEMPMS;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">28. /*+NOCACHE(TABLE)*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">当进行全表扫描时,CACHE提示能够将表的检索块放置在缓冲区缓存中最近最少列表LRU的最近使用端</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">例如:</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">SELECT /*+FULL(BSEMPMS) NOCAHE(BSEMPMS) */ EMP_NAM FROM BSEMPMS;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">29. /*+APPEND*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">直接插入到表的最后,可以提高速度.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">insert /*+append*/ into test1 select * from test4 ;</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">30. /*+NOAPPEND*/</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">通过在插入语句生存期内停止并行模式来启动常规插入.</span><br style="font-family: Arial; line-height: 26px;" /><span style="font-family: Arial; line-height: 26px;">insert /*+noappend*/ into test1 select * from test4 ;<br /><br /><br /><br /><br /><br /></span><a href="http://blog.csdn.net/tianlesoftware/article/details/4969702" style="color: #666666; text-decoration: none; font-family: 'Microsoft YaHei'; font-size: 20px; line-height: 30px; background-color: #ffffff;">参考</a>blog:http://blog.csdn.net/tianlesoftware/article/details/4969702<img src ="http://www.blogjava.net/chenying19890808/aggbug/414813.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2014-06-16 17:31 <a href="http://www.blogjava.net/chenying19890808/archive/2014/06/16/oracle_hint.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[教學]如何架設WordPress MU 多用戶部落格？</title><link>http://www.blogjava.net/chenying19890808/archive/2013/06/16/400601.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Sun, 16 Jun 2013 07:38:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/06/16/400601.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/400601.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/06/16/400601.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/400601.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/400601.html</trackback:ping><description><![CDATA[<p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">WordPress是一套很方便的個人部落格系統架設軟體，免費開放的原始碼，任何人都可以取得、修改、架設。但你知道嗎？其實WordPress除了個人部落格之外，其實還有另一個Project，就是「WordPress MU」。這個WordPress MU是多用戶的WordPress架設程式，架設成功的話就可以自己經營BSP了，自己就像無名小站站長或是痞客邦這樣的部落格服務提供商，提供給有部落格需求的使用者使用。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">雖然知道的人不多，但現在更棒的是這個WordPress MU從WordPress3.0版開始直接整合到WordPress之中，算是一項隱藏功能，需要透過一個代碼才能啟用這項服務，以往架設WordPress MU是要在額外架設，現在完全不用了，直接在自己本來的部落格系統內就可以啟用WordPress MU，有興趣的話趕快來喚醒沉睡的WordPress MU吧！</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "></p><div style="margin: 0px auto; display: table; border-collapse: separate; color: #474747; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; font-size: 15px; letter-spacing: 1px; line-height: 25.5px; text-align: justify; background-color: #ffffff; "><div style="margin: 0px auto; display: table-row; "><div style="margin: 0px auto; display: table-cell; padding-left: 45px; "><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" id="aswift_1" name="aswift_1" style="margin: 0px auto; left: 0px; position: absolute; top: 0px; "></iframe></div></div></div><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">目前全球最大的WordPress MU使用者就是WordPress.com這個免費的WordPress免費部落格服務，這個網站就是由WordPress MU系統建立的，如果把WordPress MU經營的好當然就會像那樣囉！以往MU系統是額外獨立的專案，從3.0版的WordPress就把它整合進來，不再成為一個獨立的專案程式了，現在任何WordPress的使用者都可以把自己的網站改裝成WordPress MU。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">WordPress MU被簡稱為「<strong style="margin: 0px auto; ">WPMU</strong>」，但全名其實是「<strong style="margin: 0px auto; ">WordPress Multi User</strong>」多用戶程式。這套程式之所以大家會很少聽到是因為對於一般使用者來說，用途其實不大，因為大家架設網站都是獨立架設、擁有自己的網站，很少有人和別人共用一個網址，利用他的子網域或是子資料夾架設獨立的WordPress。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">那這套程式不就沒用了嗎？其實並不然。如果你有三五好友想要擁有一個部落格，但是不想要使用常見的BSP部落格，可是如果要自架，又不會改程式碼的話，又或是另一種情況，假若你有工作上的需要，需要架設多個WordPress，可是想要同一管理，這個<a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">WordPress MU</a>就可以幫上忙了，因為他可以開通多個部落格，網站的設定統一由最大的管理者「超級管理」來處理，其他使用者只要負責使用就可以了，這樣一來對管理者來說管理輕鬆，對其他用戶來說也方便使用。</p><blockquote style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; background-color: #f4f5f7; border-bottom-width: 1px; border-bottom-color: #a5b6c8; border-top-width: 1px; border-top-color: #a5b6c8; padding: 8px 12px 8px 36px; color: #474747; "><ul style="margin: 0px; line-height: 1.7em; letter-spacing: 0.07em; padding: 0px; list-style: square; "><li style="margin: 0px auto; ">程式名稱：WordPress MU</li><li style="margin: 0px auto; ">官方網站：<a href="http://mu.wordpress.org/" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">http://mu.wordpress.org/</a></li><li style="margin: 0px auto; "><span style="margin: 0px auto; color: #ff0000; "><strong style="margin: 0px auto; ">程式下載</strong></span>：<a href="http://tw.wordpress.org/latest-zh_TW.zip" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">按這裡</a></li><li style="margin: 0px auto; "><span style="margin: 0px auto; color: #0000ff; "><strong style="margin: 0px auto; ">備註事項</strong></span>：從WordPress3.0起整合於WordPress，所以直接下載WordPress。</li></ul></blockquote><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第1步</span></strong>&nbsp;首先請您下載程式並進行WordPress的安裝，詳細安裝過程這邊不多做說明，如果不會安裝請參考：<a href="http://sofree.cc/wordpress-install/" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">如何架設安裝WordPress部落格？</a>，先將WordPress架設起來。當您的WordPress架設好後，請下載FTP內的wp-config.php檔案，在檔案內加入語法，避免加錯位置，可在「<span style="margin: 0px auto; color: #339966; ">/* 設定完成，請儲存檔案。然後開始 Blogging 吧！ */</span>」之上加入，儲存後將檔案上傳到FTP中。</p><pre style="margin-top: 15px; margin-bottom: 15px; border: 1px solid #cccccc; color: #333333; font-size: 13px; line-height: 15px; font-family: 'Courier New'; max-height: 200px; overflow: auto; padding: 10px 10px 10px 21px; width: 646.3333129882813px; letter-spacing: 0.07em; text-align: justify; background-color: #ffffff; ">  define('WP_ALLOW_MULTISITE', true);</pre><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_0.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="597" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第2步</span></strong>&nbsp;重新整理部落格後台，點擊左方【工具】&#8594;「網誌網路」，進入後請將網誌網路的標題和聯絡信箱設定好，並點擊﹝安裝﹞。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><span style="margin: 0px auto; color: #ff0000; "><strong style="margin: 0px auto; ">[請注意]</strong></span></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">如果您是從現有的部落格修改wp-config.php，想改裝成WordPress MU多用戶系統，而非剛剛新架設的WordPress，那在子網域安裝部分無法設定，系統會強制您只能使用子目錄分類，來區分每個部落格。如果您是新架設的，那會出現子網域設定，請參考後面的教學說明。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">錯誤訊息是：<span style="margin: 0px auto; color: #0000ff; ">The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.</span></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_1.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="592" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第3步&nbsp;</span></strong>一旦設定好後，就無法再變更網站結構類型了。接著請按照畫面指示的訊息新增資料。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_2.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="592" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第4步</span></strong>&nbsp;請開啟FTP連上網站後在「/public_html/wp-content」目錄下新建一個資料夾「blogs.dir」並設定資料夾屬性為「777」，因為這邊是要儲存用戶上傳的檔案。</p><div style="margin: 0px auto; color: #474747; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; font-size: 15px; letter-spacing: 1px; line-height: 25.5px; text-align: justify; background-color: #ffffff; position: relative; left: -15px; "><iframe id="ad-scupio" frameborder="0" scrolling="no" height="90" width="728" marginheight="0" marginwidth="0" src="http://adsense.scupio.com/ADPInline/ADViewer.aspx?m=1&amp;s=0,2,726,88,FFFFFF,20,FFFFFF,2,3,16,1,35,1,0,-1,1,,RB,,,,-1,,7,1,1,0&amp;fs=FFFFFF&amp;shf=&amp;ssf=fsz:11pt,lh:18px,c:0000FF,txd:n&amp;scf=fsz:9pt,lh:18px,c:333333,txd:n&amp;suf=&amp;sif=&amp;pif=90,90,1&amp;si=728,90,1;2;4;17&amp;channelid=7827&amp;wid=864,17,18&amp;PubID=lRhVRlJvEHEX&amp;CA=0.48745893873274326&amp;u=&amp;iframe=y&amp;ref=http%3A%2F%2Fwww.google.com.hk%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3Dwordpress%252Bmu%26source%3Dweb%26cd%3D5%26cad%3Drja%26ved%3D0CEUQFjAE%26url%3D%2568%2574%2574%2570%253a%252f%252f%2573%256f%2566%2572%2565%2565%252e%2563%2563%252f%2577%256f%2572%2564%2570%2572%2565%2573%2573%252d%256d%2575%252f%26ei%3DdWG9UfG8N8yfkwXo_YGACA%26usg%3DAFQjCNG69uMhPtENLkLVDVSAj6L71HkiVw%26bvm%3Dbv.47883778%2Cd.dGI" style="margin: 0px auto; "></iframe></div><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_3.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="587" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第5步</span></strong>&nbsp;接著請下載FTP根目錄中的「wp-config.php」請將WordPress後台指示的資料加入倒wp-config.php的「/* 設定完成，請儲存檔案。然後開始 Blogging 吧！ */」這句話之上，儲存然後上傳。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">語法可能如下，但不完全一樣。</p><pre style="margin-top: 15px; margin-bottom: 15px; border: 1px solid #cccccc; color: #333333; font-size: 13px; line-height: 15px; font-family: 'Courier New'; max-height: 200px; overflow: auto; padding: 10px 10px 10px 21px; width: 646.3333129882813px; letter-spacing: 0.07em; text-align: justify; background-color: #ffffff; ">define('WP_ALLOW_MULTISITE', true); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false );  $base = '/'; define( 'DOMAIN_CURRENT_SITE', 'wpblog.net.ru' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 );</pre><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_4.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="597" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第6步</span></strong>&nbsp;接著請再將FTP上的「.htaccess」檔案下載，並根據WordPress後台指示的說明將資料加入到「.htaccess」檔案中，設定好後請上傳。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">語法類似以下，但可能不完全一樣。</p><pre style="margin-top: 15px; margin-bottom: 15px; border: 1px solid #cccccc; color: #333333; font-size: 13px; line-height: 15px; font-family: 'Courier New'; max-height: 200px; overflow: auto; padding: 10px 10px 10px 21px; width: 646.3333129882813px; letter-spacing: 0.07em; text-align: justify; background-color: #ffffff; height: 237px; ">RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule&nbsp; ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule&nbsp; ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L]</pre><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_5.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="588" height="450" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第7步&nbsp;</span></strong>設定好後，請重新登入WordPress後台，如果啟動成功進入後就會看到左上角會多出一個「超級管理」，這就是WordPress MU的管理選項，可以在那邊新增用戶、設定等等，因為升級成MU之後，原本的部落格也會屬於WordPress MU的一部分，所以在畫面中會多出限制用戶的儲存空間選項，預設都是10MB的儲存空間，使用者可以自己調整。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_6.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="445" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第8步</span></strong>&nbsp;點擊【超級管理】&#8594;﹝選項﹞可以對MU站點做設定，不過這有些部分的中文描述好像怪怪的，有點不通順就是了。設定上大家自己可以玩玩看囉！</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_7.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="445" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第9步</span></strong>&nbsp;點擊【超級管理】中的「網誌」則可以建立新網誌，就是開一個獨立的部落格，開設在子資料夾內。輸入您要的網站名稱在網誌位址以及網誌標題和該網誌站長的聯絡信箱就可以了，伺服器將會自動寄信通知部落格使用者。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_8.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="445" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第10步</span></strong>&nbsp;在網誌的清單中可以點擊您剛剛建立的部落格，點進去後可以對部落格做一些設定與調整，當然也可以保持預設不動作。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_9.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="445" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第11步</span></strong>&nbsp;建立好的部落格就像這樣子囉！</p><blockquote style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; background-color: #f4f5f7; border-bottom-width: 1px; border-bottom-color: #a5b6c8; border-top-width: 1px; border-top-color: #a5b6c8; padding: 8px 12px 8px 36px; color: #474747; "><ul style="margin: 0px; line-height: 1.7em; letter-spacing: 0.07em; padding: 0px; list-style: square; "><li style="margin: 0px auto; "><strong style="margin: 0px auto; ">主站</strong>：<a href="http://twz.cz.cc/" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">http://twz.cz.cc/</a></li><li style="margin: 0px auto; "><strong style="margin: 0px auto; ">子網站</strong>：<a href="http://twz.cz.cc/happy/" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">http://twz.cz.cc/happy/</a></li></ul></blockquote><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_10.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="445" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></p><h2>WordPress MU 設定子網域</h2><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">前面有提到，如果是新安裝的WordPress，那在您啟動WordPress MU功能同時，設定選項中會讓使用者選擇「子網域」或是「子目錄」。當然設定成子網域會比較好看，網址感覺高級一點，但相對的困難度也提高，因為需要動到系統設定檔案，目前網路上還沒有一個教學是針對「虛擬主機(Share Hosting)」，因為需要動到系統的阿帕契和DNS之類的設定，所以非常的麻煩。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><span style="margin: 0px auto; color: #008000; "><strong style="margin: 0px auto; ">第1步</strong></span>&nbsp;如果是新架設的WordPress，在啟動MU功能時，會在【工具】&#8594;「網誌網路」中看見「子網域」和「子目錄」的設定，請您選擇子網域進行設定。請記住這邊一但選擇了網站架構，就不能進行更改，如果強制更改原始碼，可能會出現無法意料的錯誤。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_11.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="442" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第2步</span></strong>&nbsp;接著WordPress會偵測您的空間是否有辦法自動建立子網域，但在虛擬主機中，實驗的結果都是會失敗的，因為一般使用者沒有權限去調整伺服器的設定。以最常見的虛擬主機系統cPanel來說，用戶無法對其網址進行變更，必須由cPanel管理者透過WHM內的DNS功能進行調整才行。如果您是自架主機，基本上應該就有權限可以設定，因此請先根據這頁面內的資料把網站設定一下，這邊的設定就跟前面提到的部分是一樣的，因此就不多做說明。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_12.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="442" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第3步</span></strong>&nbsp;接著就是設定伺服器或虛擬主機以及網址部份了。關於虛擬主機要設定的「Wildcard DNS Record」等等之類的，以下有幾篇教學可以參考看看：<a href="http://blog.hi3b.com/archives/192" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">這裡</a>、<a href="http://vbb.twftp.org/showthread.php?t=11605" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">這裡</a>、<a href="http://codex.wordpress.org/Create_A_Network" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">這裡</a>。如果虛擬主機支援的話，只要到DNS代管站新增一筆A紀錄，然後網域部分請輸入通用符號「<span style="margin: 0px auto; color: #ff0000; ">*</span>」，然後再輸入IP並新增就可以了。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">大部分DNS代管站都可以，當然仍是有可能不支援的，目前測試的<a href="http://sofree.cc/godaddy-free-dns/" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">GoDaddy</a>是可以新增前面提到所謂的「<span style="margin: 0px auto; color: #ff0000; "><strong style="margin: 0px auto; ">Wildcard DNS Record</strong></span>」資料。</p><blockquote style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; background-color: #f4f5f7; border-bottom-width: 1px; border-bottom-color: #a5b6c8; border-top-width: 1px; border-top-color: #a5b6c8; padding: 8px 12px 8px 36px; color: #474747; "><p style="margin: 15px 0px; line-height: 1.7em; letter-spacing: 0.07em; ">You can create a wildcard A record by setting the Host Name value to &#8220;*" (asterisk). The wildcard causes the server to respond with the IP address specified instead of an error if the subdomain queried does not exist within your zone file.</p></blockquote><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_dns.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="442" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #008000; ">第4步</span></strong>&nbsp;設定好後，您可以自由的新增部落格，新增部落格的時候會發現網誌位址部分變成讓使用者輸入網域囉！</p><blockquote style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; background-color: #f4f5f7; border-bottom-width: 1px; border-bottom-color: #a5b6c8; border-top-width: 1px; border-top-color: #a5b6c8; padding: 8px 12px 8px 36px; color: #474747; "><p style="margin: 15px 0px; line-height: 1.7em; letter-spacing: 0.07em; ">以下展示網站為<a href="http://shachi.tw/" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">殺氣</a>測試，使用<a href="http://shachi.tw/signup-h-sphere/" rel="nofollow" target="_blank" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">H-Sphere空間</a>作為測試！</p><p style="margin: 15px 0px; line-height: 1.7em; letter-spacing: 0.07em; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #ff0000; ">主</span>網域部落格</strong>：<a href="http://tgcc.org.ru/" rel="nofollow" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">http://tgcc.org.ru/</a></p><p style="margin: 15px 0px; line-height: 1.7em; letter-spacing: 0.07em; "><strong style="margin: 0px auto; "><span style="margin: 0px auto; color: #0000ff; ">子</span>網域部落格</strong>：<a href="http://happy.tgcc.org.ru/" rel="nofollow" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">http://happy.tgcc.org.ru/</a></p></blockquote><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; "><a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; "><img title="[教學]如何架設WordPress MU 多用戶部落格？" src="http://img2.sofree.cc/2011/e666ff24b572_11DCE/wp_mu_13.png" border="0" alt="[教學]如何架設WordPress MU 多用戶部落格？" width="600" height="442" data-pinit="registered" style="margin: 0px auto; border: 0px; max-width: 600px; display: inline; " /></a></p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">基本上設定就是這樣子而已，其實如果不使用子網域，一般虛擬主機都可以很輕鬆的啟用WordPress MU多用戶功能。不過有些人可能啟用會失敗，那就是主機不支援不支援固定網址的功能，您的Apache的「mod_rewrite」這個模組被禁用了，如果是個人用戶可以到系統檔案「httpd.conf」把分號去掉，如果是虛擬主機請聯絡管理員。</p><p style="margin: 15px 0px; font-size: 15px; line-height: 25.5px; font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, sans-serif; letter-spacing: 1px; text-align: justify; color: #474747; background-color: #ffffff; ">如果你本身沒有多用戶需求，建議不要啟動MU，因為啟動MU之後，部落格的資料庫會多一些資料表，每建立一個部落格，就會多出10多張的資料表。另外，啟動<a href="http://sofree.cc/wordpress-mu/" style="margin: 0px auto; color: #0066cc; text-decoration: none; outline: none medium; ">MU</a>之後系統資源也會吃比較重，因為就等於在一個網站上架設好幾個部落格在運作，只是管理上比獨立架設方便，如果您有需要架設MU，最好要挑選一個限制比較少的虛擬主機來架設，否則三天兩頭資源就吃完了，空間被停是早晚的事情。</p><img src ="http://www.blogjava.net/chenying19890808/aggbug/400601.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-06-16 15:38 <a href="http://www.blogjava.net/chenying19890808/archive/2013/06/16/400601.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>两个WordPress共享同一个用户数据库表教程</title><link>http://www.blogjava.net/chenying19890808/archive/2013/06/15/400577.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Sat, 15 Jun 2013 11:53:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/06/15/400577.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/400577.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/06/15/400577.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/400577.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/400577.html</trackback:ping><description><![CDATA[<h1><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">这两天在全力设计<a title="东方设计图库频道" href="http://tuku.eastdesign.net/" target="_blank" style="color: #21759b; text-decoration: none; ">东方设计图库频道</a>&nbsp;期间尝试了多种办法来尽可能的与<a href="http://www.eastdesign.net/" title="东方设计工作室" target="_blank" style="color: #333333; text-decoration: none; ">东方设计工作室</a>主站集成在一起，起初尝试了<a href="http://www.eastdesign.net/wordpress-web-development/" title="WordPress" target="_blank" style="color: #333333; text-decoration: none; ">WordPress</a>的Multisite功能，分别以Sub directory和Sub domain的形式分别各自试了一次，发觉，WP一旦开启了Multisite以后结构变得复杂了很多，而且不够稳定，数据库表也一下子飙升了很多，显得非常臃肿，显然这个并不是我所要的效果，于是经过整个周末的来回尝试，最后放弃了Multisite的形式，还是全新安装了一个WP，经过反复调试，已经初具模型，但是问题就是用户也得重新注册一次，这个显然再次违背了我的初衷，经过反复Google，终于找到了一个完美的解决方案，那就是两个完全独立的WordPress共享同一个数据表，堪称完美，不敢独享，现将教程共享给各位。</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">因为图库站新建的WP已经搭建出来了，而这个集成必须是后边这个WP需要在共享前一个数据库的用户表的基础上全新安装才可以实现，而且两个WP必须建在同一个数据库里边，这个问题不大，只要改变一下前缀即可，于是说干就敢。</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">第一步、通过WP的工具》导出功能将已经建立好的文章页面等统统导出成一个XML文件；</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">第二步、修改新建的WP的配置文件wp-config.php如下所示：</p><blockquote style="background-image: url(http://cdn3.eastdesign.net/wp-content/themes/eastdesign/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; border-color: #eeeeee; color: #006600; font-size: 9pt; line-height: 2em; margin: 15px 10px; padding-right: 5px; padding-left: 35px; font-family: Arial, Helvetica, sans-serif; font-weight: normal; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><p style="color: #333333; margin: 10px; ">$table_prefix = &#8216;blogb_&#8217;;</p></blockquote><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">修改数据库表前缀为新的前缀，防止和第一个WP冲突，然后在同个文件里找到</p><blockquote style="background-image: url(http://cdn3.eastdesign.net/wp-content/themes/eastdesign/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; border-color: #eeeeee; color: #006600; font-size: 9pt; line-height: 2em; margin: 15px 10px; padding-right: 5px; padding-left: 35px; font-family: Arial, Helvetica, sans-serif; font-weight: normal; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><p style="color: #333333; margin: 10px; ">/* That&#8217;s all, stop editing! Happy blogging. */</p></blockquote><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">在这断话上方插入：</p><blockquote style="background-image: url(http://cdn3.eastdesign.net/wp-content/themes/eastdesign/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; border-color: #eeeeee; color: #006600; font-size: 9pt; line-height: 2em; margin: 15px 10px; padding-right: 5px; padding-left: 35px; font-family: Arial, Helvetica, sans-serif; font-weight: normal; background-position: 0% 0%; background-repeat: no-repeat no-repeat; "><p style="color: #333333; margin: 10px; ">define(&#8216;CUSTOM_USER_TABLE&#8217;, &#8216;wp_users&#8217;); define(&#8216;CUSTOM_USER_META_TABLE&#8217;, &#8216;wp_usermeta&#8217;);</p></blockquote><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">注意这里的wp_users和wp_usermeta都是第一个WP的用户数据表，这里我们假设第一个WP用了默认的前缀；</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">第三步、修改完配置文件以后，就可以开始安装第二个WP，安装过程不是本教程讨论的范畴，因此略过；</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">第四步、安装完成你会发现可以直接用第一个WP网站的管理员直接登陆第二个WP网站后台，然后进入工具》导入，将第一步导出的XML文件重新导入，然后进行一些必要的配置即可。</p><p style="color: #333333; line-height: 26px; margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal; background-color: #ffffff; ">搞定收工，经过测试非常完美，至此，在任意第一个或者第二个上新注册的用户，立马可以直接用来登陆另外一个网站的后台，Fantastic，所谓踏破铁鞋无觅处、得来全不费工夫，这几天的忙活没有白费，有了这个方法，理论上你可以设置任意多个独立的WP系统共用同一个用户数据表，有点类似于discuz的ucenter，但是这个显然整合的更彻底，直接就是同一个表，不用担心还需要再次同步的问题。</p></h1><img src ="http://www.blogjava.net/chenying19890808/aggbug/400577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-06-15 19:53 <a href="http://www.blogjava.net/chenying19890808/archive/2013/06/15/400577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>两种wordpress更换后台登录界面logo图标方</title><link>http://www.blogjava.net/chenying19890808/archive/2013/06/09/400451.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Sun, 09 Jun 2013 11:57:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/06/09/400451.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/400451.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/06/09/400451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/400451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/400451.html</trackback:ping><description><![CDATA[<div style="color: #333333; line-height: 24px; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "><div exp-content-blog-body"="" style="text-align: justify; margin-top: 40px; "><div><div><p style="margin: 6px 0px; padding: 0px; ">wordpress网站后台登陆界面有个Logo图标，在自己的网站摆着官方的图标，很多人看起来很不舒服，所以大家都希望更换掉这个图标，为此，小编推荐两种wordpress更换图标的方法：</p><ul list-paddingleft-1"="" style="margin: 0px; padding: 0px; list-style: none; clear: both; "><li list-disc-paddingleft"="" style="margin: auto !important; padding: 0px 0px 0px 41px !important; background-image: url(http://img.baidu.com/img/iknow/exp/global/unsortlist.png); background-attachment: scroll; background-color: transparent; float: none !important; background-position: 11px 7px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; "><strong>第一种方法：只需要把其原本调用的logo图片替换为自己的logo图片即可，具体步骤如下：</strong></p></li></ul><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;准备一张命名为logo-login.gif的背景透明的图片大小规格为310px*70px</p><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在wordpress根目录的wp-admin/images文件夹中找到logo-login.gif文件，</p><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用这张图片覆盖替换为自己准备好的logo-login.gif图片即可</p><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;访问后台登陆界面，图标已更换。</p><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;优点：简单，快捷，适合新手使用；</p><p style="margin: 6px 0px; padding: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;缺点：更新升级版本时又得重新修改。</p><ul list-paddingleft-1"="" style="margin: 0px; padding: 0px; list-style: none; clear: both; "><li list-disc-paddingleft"="" style="margin: auto !important; padding: 0px 0px 0px 41px !important; background-image: url(http://img.baidu.com/img/iknow/exp/global/unsortlist.png); background-attachment: scroll; background-color: transparent; float: none !important; background-position: 11px 7px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; "><strong>第二种方法、在functions.php修改，具体步骤如下：</strong></p></li></ul><ol list-paddingleft-1"="" style="margin: 0px; padding: 0px; list-style: none; clear: both; "><li list-decimal-paddingleft-1"="" style="margin: 0px; padding: 9px 0px 22px 42px !important; background-image: url(http://img.baidu.com/img/iknow/exp/edit/edit-num1.png); min-height: 20px; height: auto; zoom: 1; background-position: 0px 4px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; ">在主题函数文件functions.php中，添加如下一行，以修改链接地址：</p><p style="margin: 0px; padding: 0px; ">add_filter(&#8216;login_headerurl&#8217;, create_function(false,&#8217;return get_bloginfo(&#8216;siteurl&#8217;);&#8221;));</p></li><li list-decimal-paddingleft-1"="" style="margin: 0px; padding: 9px 0px 22px 42px !important; background-image: url(http://img.baidu.com/img/iknow/exp/edit/edit-num2.png); min-height: 20px; height: auto; zoom: 1; background-position: 0px 4px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; ">在主题函数文件functions.php中，添加如下一行，以修改链接地址的标题提示：</p><p style="margin: 0px; padding: 0px; ">add_filter(&#8216;login_headertitle&#8217;, create_function(false,&#8221;return get_bloginfo(&#8216;description&#8217;);&#8221;));</p></li><li list-decimal-paddingleft-1"="" style="margin: 0px; padding: 9px 0px 22px 42px !important; background-image: url(http://img.baidu.com/img/iknow/exp/edit/edit-num3.png); min-height: 20px; height: auto; zoom: 1; background-position: 0px 4px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; ">在主题函数文件functions.php中，添加如下内容，以修改由CSS控制显示的链接图片：</p><p style="margin: 0px; padding: 0px; ">function nowspark_login_head() {&nbsp;&nbsp;&nbsp; echo &#8216;&lt;style type=&#8221;text/css&#8221;&gt;body.login #login h1 a {background:url(http://www.mengzhiyi.info/wp-content/themes/mengzhiyi/images/buttom_logo.gif) no-repeat 0 0 transparent;height: 31px;width: 155px;padding:0;margin:0 auto 1em;}&lt;/style&gt;&#8217;;}add_action(&#8220;login_head&#8221;, &#8220;nowspark_login_head&#8221;);//modify the background image</p></li><li list-decimal-paddingleft-1"="" style="margin: 0px; padding: 9px 0px 22px 42px !important; background-image: url(http://img.baidu.com/img/iknow/exp/edit/edit-num4.png); min-height: 20px; height: auto; zoom: 1; background-position: 0px 4px; background-repeat: no-repeat no-repeat; "><p style="margin: 0px; padding: 0px; ">将url中链接修改为你自己的链接即可！</p></li></ol><p style="margin: 6px 0px; padding: 0px; ">优点：更新版本无需重新更改，更改图片的同时把链接地址和标题提示也同时修改掉了；（本站推荐使用方法）</p><p style="margin: 6px 0px; padding: 0px; "></p></div></div></div></div><div id="auto-app-placehold" style="font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><div "="" style="color: #333333; line-height: 24px; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "><h2>参考资料</h2><div reference"="" id="exp-reference-id" style="padding-right: 10px; padding-left: 10px; text-align: justify; margin-top: 5px; "><a href="http://www.mengzhiyi.info/589.html" target="_blank" rel="nofollow" style="text-decoration: none; color: #2d64b3; ">http://www.mengzhiyi.info/589.html</a></div></div><img src ="http://www.blogjava.net/chenying19890808/aggbug/400451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-06-09 19:57 <a href="http://www.blogjava.net/chenying19890808/archive/2013/06/09/400451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Rails 更改和验证相关的错误显示消息</title><link>http://www.blogjava.net/chenying19890808/archive/2013/04/21/398158.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Sun, 21 Apr 2013 07:22:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/04/21/398158.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/398158.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/04/21/398158.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/398158.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/398158.html</trackback:ping><description><![CDATA[<a href="http://pragprog.com/wikis/wiki/RailsPlayTime">http://pragprog.com/wikis/wiki/RailsPlayTime</a>&nbsp;<img src ="http://www.blogjava.net/chenying19890808/aggbug/398158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-04-21 15:22 <a href="http://www.blogjava.net/chenying19890808/archive/2013/04/21/398158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Rails 305安装以及Rake版本修改</title><link>http://www.blogjava.net/chenying19890808/archive/2013/04/20/398139.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Sat, 20 Apr 2013 13:39:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/04/20/398139.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/398139.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/04/20/398139.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/398139.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/398139.html</trackback:ping><description><![CDATA[<a href="http://wenku.baidu.com/view/e18f5cd3b14e852458fb5761.html###">http://wenku.baidu.com/view/e18f5cd3b14e852458fb5761.html###</a>&nbsp;<img src ="http://www.blogjava.net/chenying19890808/aggbug/398139.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-04-20 21:39 <a href="http://www.blogjava.net/chenying19890808/archive/2013/04/20/398139.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>gem update --system 302 错误 解决方案（转）</title><link>http://www.blogjava.net/chenying19890808/archive/2013/02/05/395132.html</link><dc:creator>wokaoJune</dc:creator><author>wokaoJune</author><pubDate>Tue, 05 Feb 2013 06:13:00 GMT</pubDate><guid>http://www.blogjava.net/chenying19890808/archive/2013/02/05/395132.html</guid><wfw:comment>http://www.blogjava.net/chenying19890808/comments/395132.html</wfw:comment><comments>http://www.blogjava.net/chenying19890808/archive/2013/02/05/395132.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chenying19890808/comments/commentRss/395132.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chenying19890808/services/trackbacks/395132.html</trackback:ping><description><![CDATA[具体过程如下：&nbsp;<br /><br />1、InstantRails-2.0安装后，在配置环境变量path中配置ruby/bin目录（如果系统中有多个RUBY，执行命令行的时候系统认的就是path中的）&nbsp;<br /><br />2、进入DOS命令行，执行gem&nbsp;update&nbsp;--system，结果&nbsp;<br /><br />Updating&nbsp;RubyGems...&nbsp;<br />ERROR:&nbsp;&nbsp;While&nbsp;executing&nbsp;gem&nbsp;...&nbsp;(Gem::RemoteSourceException)&nbsp;<br />HTTP&nbsp;Response&nbsp;302&nbsp;fetching&nbsp;http://rubygems.org/yaml&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这是因为gem的配置过低，无法进行远程更新，执行gem&nbsp;-v&nbsp;发现是1.0.1&nbsp;<br /><br />3、从下面这个地址下载&nbsp;rubygems-update-1.3.7.gem，http://rubyforge.org/frs/download.php/70695/rubygems-update-1.3.7.gem&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;然后DOS命令进行该文件所在的目录，执行gem&nbsp;install&nbsp;--local&nbsp;rubygems-update-1.3.7.gem，出现信息&nbsp;<br /><br />Successfully&nbsp;installed&nbsp;rubygems-update-1.3.7&nbsp;<br />1&nbsp;gem&nbsp;installed&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;rubygems-update-1.3.7...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;rubygems-update-1.3.7...&nbsp;<br />Could&nbsp;not&nbsp;find&nbsp;main&nbsp;page&nbsp;README&nbsp;<br />Could&nbsp;not&nbsp;find&nbsp;main&nbsp;page&nbsp;README&nbsp;<br />Could&nbsp;not&nbsp;find&nbsp;main&nbsp;page&nbsp;README&nbsp;<br />Could&nbsp;not&nbsp;find&nbsp;main&nbsp;page&nbsp;README&nbsp;<br /><br />&nbsp;&nbsp;执行gem&nbsp;-v查看，发现并没有更新成功，Could&nbsp;not&nbsp;find&nbsp;main&nbsp;page&nbsp;README是什么意思我没弄明白，但是我从http://production.s3.rubygems.org/yaml上发现这么一句&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;you&nbsp;have&nbsp;an&nbsp;older&nbsp;version&nbsp;of&nbsp;RubyGems&nbsp;installed,&nbsp;then&nbsp;you&nbsp;can&nbsp;still&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;it&nbsp;in&nbsp;two&nbsp;steps:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$&nbsp;gem&nbsp;install&nbsp;rubygems-update&nbsp;&nbsp;#&nbsp;again,&nbsp;might&nbsp;need&nbsp;to&nbsp;be&nbsp;admin/root&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$&nbsp;update_rubygems&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;...&nbsp;here&nbsp;too&nbsp;<br />我照着再执行&nbsp;update_rubygems，接着出现的信息很多，就不帖出来，再执行gem&nbsp;-v，发现更新成功，已经是1.3.7了&nbsp;<br /><br />这一步是一切成功的源泉！！！！！！&nbsp;<br /><br />4、接着再执行gem&nbsp;update&nbsp;--system，提示&nbsp;<br /><br />Updating&nbsp;RubyGems&nbsp;<br />Nothing&nbsp;to&nbsp;update&nbsp;<br /><br />&nbsp;&nbsp;这是为什么我不明白，请高手指点一下&nbsp;<br /><br />5、再执行gem&nbsp;update&nbsp;rails&nbsp;--include-dependencies，提示信息&nbsp;<br /><br />Updating&nbsp;installed&nbsp;gems&nbsp;<br />Updating&nbsp;rails&nbsp;<br />ERROR:&nbsp;&nbsp;Error&nbsp;installing&nbsp;rails:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actionpack&nbsp;requires&nbsp;rack&nbsp;(~&gt;&nbsp;1.0.0,&nbsp;runtime)&nbsp;<br />Gems&nbsp;updated:&nbsp;activesupport,&nbsp;activerecord&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;activesupport-2.3.3...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;activerecord-2.3.3...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;activesupport-2.3.3...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;activerecord-2.3.3...&nbsp;<br /><br />执行rails&nbsp;-v，发现还是2.0.2没有更新成功，根据actionpack&nbsp;requires&nbsp;rack&nbsp;(~&gt;&nbsp;1.0.0,&nbsp;runtime)，应该是actionpack&nbsp;需要1.0.0版本的rack&nbsp;<br /><br />6、执行gem&nbsp;install&nbsp;rack&nbsp;-v=1.0.0&nbsp;<br /><br />Successfully&nbsp;installed&nbsp;rack-1.0.0&nbsp;<br />1&nbsp;gem&nbsp;installed&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;rack-1.0.0...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;rack-1.0.0...&nbsp;<br /><br />更新成功&nbsp;<br /><br />7、再次执行&nbsp;gem&nbsp;update&nbsp;rails&nbsp;--include-dependencies&nbsp;<br /><br />出现信息&nbsp;<br /><br />Updating&nbsp;installed&nbsp;gems&nbsp;<br />Updating&nbsp;rails&nbsp;<br />Successfully&nbsp;installed&nbsp;rake-0.8.7&nbsp;<br />Successfully&nbsp;installed&nbsp;activesupport-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;activerecord-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;rack-1.1.0&nbsp;<br />Successfully&nbsp;installed&nbsp;actionpack-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;actionmailer-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;activeresource-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;rails-2.3.8&nbsp;<br />Gems&nbsp;updated:&nbsp;rake,&nbsp;activesupport,&nbsp;activerecord,&nbsp;rack,&nbsp;actionpack,&nbsp;actionmailer,&nbsp;activeresource,&nbsp;rails&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;rake-0.8.7...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;activesupport-2.3.8...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;activerecord-2.3.8...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;rack-1.1.0...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;actionpack-2.3.8...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;actionmailer-2.3.8...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;activeresource-2.3.8...&nbsp;<br />Installing&nbsp;ri&nbsp;documentation&nbsp;for&nbsp;rails-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;rake-0.8.7...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;activesupport-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;activerecord-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;rack-1.1.0...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;actionpack-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;actionmailer-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;activeresource-2.3.8...&nbsp;<br />Installing&nbsp;RDoc&nbsp;documentation&nbsp;for&nbsp;rails-2.3.8...&nbsp;<br /><br />执行rails&nbsp;-v，发现已更新成功&nbsp;<br /><br /><br /><br />总结：rails更新有两种方式：1、联机更新;2本地更新&nbsp;<br /><br />联机更新过程中如果出现HTTP&nbsp;Response&nbsp;302&nbsp;fetching&nbsp;http://rubygems.org/yaml无法更新，有两种情况&nbsp;<br /><br />一是gem的版本过低，二是与服务器的连接不通&nbsp;<br /><br />此时可以试着加入其他服务器地址&nbsp;<br /><br />gem&nbsp;source&nbsp;-l&nbsp;&nbsp;查看列表&nbsp;<br /><br />gem&nbsp;source&nbsp;-a&nbsp;http://rubygems.org&nbsp;加入新的服务器地址&nbsp;<br /><br />或者直接gem&nbsp;install&nbsp;rubygems-update&nbsp;--source&nbsp;http://rubygems.org&nbsp;<br /><br />本地更新需要下载相应的gem包，版本需与要更新的rails版本对应，同时安装顺序有要求，因此gem包之间有依赖关系&nbsp;<br /><br />顺序从上面的显示信息中可以看出来&nbsp;<br /><br />Successfully&nbsp;installed&nbsp;rake-0.8.7&nbsp;<br />Successfully&nbsp;installed&nbsp;activesupport-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;activerecord-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;rack-1.1.0&nbsp;<br />Successfully&nbsp;installed&nbsp;actionpack-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;actionmailer-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;activeresource-2.3.8&nbsp;<br />Successfully&nbsp;installed&nbsp;rails-2.3.8&nbsp;<br /><br />至于gem包的下载地址都在http://rubyforge.org/，但是有些项目的并不好找到，可以在google中直接搜索，就能找到在http://rubyforge.org/中的地址。<img src ="http://www.blogjava.net/chenying19890808/aggbug/395132.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chenying19890808/" target="_blank">wokaoJune</a> 2013-02-05 14:13 <a href="http://www.blogjava.net/chenying19890808/archive/2013/02/05/395132.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>