tag:blogger.com,1999:blog-13991647275951928642011-02-25T02:26:47.552-08:00iPhone碎碎念iPhone開發筆記,給健忘的老人用的。Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-1399164727595192864.post-84984265823574304642011-02-25T02:26:00.001-08:002011-02-25T02:26:47.560-08:002011-02-25T02:26:47.560-08:00App Store Quick Reference: Getting Started with In App Purchase on iPhone OS Version 2.0<a href="http://developer.apple.com/news/ios/pdf/in_app_purchase.pdf">http://developer.apple.com/news/ios/pdf/in_app_purchase.pdf</a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-8498426582357430464?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-76579295173641335042011-02-20T21:32:00.000-08:002011-02-20T21:32:01.798-08:002011-02-20T21:32:01.798-08:00NSURLConnection <span class="Apple-style-span" style="color: #333333; font-family: Verdana, Geneva, Lucida; font-size: 15px; line-height: 22px;">在預設的情況下,一個 iPhone App 只有一條執行緒(Thread),簡單的說就是同一時間只能做一件事,所以當你用 NSData 或 NSString 的 initWithContentsOfURL 的方法來載入網頁資料時,整個程式就會停在那裡,直到網頁資料都下載完了後,才會繼續執行下一行的程式碼。繼然程式停在那不動,當然你不論怎麼加上其它的動畫或View都不會有作用,這就是我昨天一直失敗的原因。<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />所以有兩種方式來解決這個問題,一是自己開 Thread 來用時做好幾件事,二是使用委託處理的方式,把要做的事情委託出去,等事情做完後,被委託的人會通知你事情已經處理完了。這也就是 iOS 一直強調的 delgate model。<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />自己開 Thread 並不適合用在 iT邦幫忙 App 裡,因為我必需要知道網頁資料何時會下載完畢,等下載完畢後,再把載入等待畫面給移除。所以我需要找到一個能幫我下載網頁資料,然後下載完後能通知我的一個類別,那個就是 - NSURLConnection。<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />NSURLConnection 宣告使用的程式碼如下:</span><br />
<div class="dp-highlighter" style="background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; margin-bottom: 18px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 18px !important; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 1px; width: 596px;"><div class="bar" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 45px; padding-right: 0px; padding-top: 0px;"><div class="tools" style="background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 10px; padding-left: 10px; padding-right: 8px; padding-top: 3px;"><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">檢視原始檔</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">複製到剪貼簿</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">列印</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">關於</a></div></div><ol class="dp-cpp" start="1" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; list-style-image: initial; list-style-position: initial; list-style-type: decimal; margin-bottom: 1px !important; margin-left: 45px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@</span><span class="string" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">"http://ithelp.ithome.com.tw/?tab=share"</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">]]; </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[NSURLConnection connectionWithRequest:request delegate:self]; </span></li>
</ol></div><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />它需要兩個參數,一個是 NSURLRequest 物件,另一個是 delegate 物件。上面的程式碼把 delegate 指向自己(self),也就是目前所在的類別來接受 NSURLConnect 的事件。最重要的有四個事件處理的方法:<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><div class="dp-highlighter" style="background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; margin-bottom: 18px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 18px !important; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 1px; width: 596px;"><div class="bar" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 45px; padding-right: 0px; padding-top: 0px;"><div class="tools" style="background-color: #f8f8f8; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; color: silver; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 10px; padding-left: 10px; padding-right: 8px; padding-top: 3px;"><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">檢視原始檔</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">複製到剪貼簿</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">列印</a><a href="http://ithelp.ithome.com.tw/question/10058407#" style="background-attachment: initial; background-clip: initial; background-color: inherit; background-image: none; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #a0a0a0; font-size: 9px; margin-bottom: 0px; margin-left: 0px; margin-right: 10px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;">關於</a></div></div><ol class="dp-cpp" start="1" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; list-style-image: initial; list-style-position: initial; list-style-type: decimal; margin-bottom: 1px !important; margin-left: 45px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="comment" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #008200; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">//是否收到網站的回應</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">- (<span class="keyword" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #006699; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">void</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [htmlData setLength:0]; </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} </span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="comment" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #008200; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">//收到網站傳回的資料</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">- (<span class="keyword" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #006699; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">void</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [htmlData appendData:data]; </span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="comment" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #008200; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">//網頁資料下載完畢</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">- (<span class="keyword" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #006699; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">void</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">)connectionDidFinishLoading:(NSURLConnection *)connection { </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> NSLog(@<span class="string" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">"Succeeded! Received %d bytes of data"</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">,[htmlData length]); </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> NSLog(@<span class="string" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">"%@"</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">, [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding]); </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="comment" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #008200; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">//網路連線錯誤</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> </span></span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">- (<span class="keyword" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: #006699; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">void</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [connection release]; </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> NSLog(@<span class="string" style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">"Connection failed! Error - %@ %@"</span><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">, </span></span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [error localizedDescription], </span></li>
<li class="" style="background-color: #f8f8f8; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: #5c5c5c; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); </span></li>
<li class="alt" style="background-color: white; border-bottom-style: none; border-color: initial; border-left-color: rgb(108, 226, 108); border-left-style: solid; border-left-width: 3px; border-right-style: none; border-top-style: none; border-width: initial; color: inherit; line-height: 14px; list-style-image: initial; list-style-position: outside !important; list-style-type: decimal-leading-zero; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important; padding-bottom: 0px !important; padding-left: 10px !important; padding-right: 3px !important; padding-top: 0px !important;"><span style="background-color: inherit; border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; color: black; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} </span></li>
</ol></div><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />htmlData 是個 NSMutableData 的物件,當 NSURLConnect 連上網站時,我先把 htmlData 清空準備來接收網頁資料。NSURLConnection 會把網頁資料一段一段下載回來,每當下載一部份時,didReceiveData 方法會收到通知,這時我把資頁資料給存放進 htmlData 物件裡。等到全部下載回來後,會呼叫 connectionDidFinishLoading 方法,這時我就把網頁的資料給印出來...<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" />當下載的過程中發生錯誤時,會呼叫 didFailWithError 的方法,這時我會印出錯誤訊息,看看發生了什麼事。<br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-7657929517364133504?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-69380975357551201892011-02-16T22:14:00.001-08:002011-02-16T22:14:54.112-08:002011-02-16T22:14:54.112-08:00【IOS】消息通信機制NSNotificationCenter<span class="Apple-style-span" style="border-collapse: collapse; font-family: song, Verdana; font-size: 12px;"></span><br />
<div>最近寫程序需要用到這類,研究了下,現把成果和大家分享。<br style="font: normal normal normal 12px/normal song, Verdana;" />NSNotificationCenter是專門供程序中不同類間的消息通信而設置的,使用起來極為方便,<br style="font: normal normal normal 12px/normal song, Verdana;" /><br style="font: normal normal normal 12px/normal song, Verdana;" />設置通知,就是說要在什麼地方(哪個類)接受通知,一般在初始化中做。</div><div><table bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0" style="border-collapse: collapse;"><tbody>
<tr style="font: normal normal normal 12px/normal song, Verdana;"><td style="font: normal normal normal 12px/normal song, Verdana;"><div style="font: normal normal normal 12px/normal song, Verdana; line-height: 18px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px; margin-top: 5px;"><code><span style="color: black;"><span style="font-family: NSimsun;"><span style="color: #0000cc;">[</span><span style="color: #0000cc;">[</span>NSNotificationCenter defaultCenter<span style="color: #0000cc;">]</span> addObserver<span style="color: #0000cc;">:</span>self selector<span style="color: #0000cc;">:</span><span style="color: #0000cc;">@</span>selector<span style="color: #0000cc;">(</span><span style="color: red;">test</span><span style="color: #0000cc;">:</span><span style="color: #0000cc;">)</span> name<span style="color: #0000cc;">:</span><span style="color: #0000cc;">@</span><span style="color: magenta;">" test"</span> object<span style="color: #0000cc;">:</span>nil<span style="color: #0000cc;">]</span><span style="color: #0000cc;">;</span></span></span></code></div></td></tr>
</tbody></table></div><div>我僅對以上參數做以說明:addObserver 這個是觀察者,就是說 在什麼地方接收通知;<br style="font: normal normal normal 12px/normal song, Verdana;" /> selector 這個是收到通知後,調用何種方法;<br style="font: normal normal normal 12px/normal song, Verdana;" /> name: 這個是通知的名字,也是通知的唯一標示,編譯器就通過這個找到通知的。<br style="font: normal normal normal 12px/normal song, Verdana;" />發送通知,就是說此時要調用觀察者處的方法。</div><div><table bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0" style="border-collapse: collapse;"><tbody>
<tr style="font: normal normal normal 12px/normal song, Verdana;"><td style="font: normal normal normal 12px/normal song, Verdana;"><div style="font: normal normal normal 12px/normal song, Verdana; line-height: 18px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px; margin-top: 5px;"><code><span style="color: black;"><span style="font-family: NSimsun;"><span style="color: #0000cc;">[</span><span style="color: #0000cc;">[</span>NSNotificationCenter defaultCenter<span style="color: #0000cc;">]</span> postNotificationName<span style="color: #0000cc;">:</span><span style="color: #0000cc;">@</span><span style="color: magenta;">"test"</span> object<span style="color: #0000cc;">:</span>searchFriendArray<span style="color: #0000cc;">]</span><span style="color: #0000cc;">;</span></span></span></code></div></td></tr>
</tbody></table></div><div>我僅對以上參數做以說明:<br style="font: normal normal normal 12px/normal song, Verdana;" />postNotificationName:通知的名字,也是通知的唯一標示,編譯器就通過這個找到通知的。<br style="font: normal normal normal 12px/normal song, Verdana;" />object:傳遞的參數<br style="font: normal normal normal 12px/normal song, Verdana;" />發送通知時,默認調用test方法。</div><table bgcolor="#f1f1f1" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0" style="border-collapse: collapse;"><tbody>
<tr style="font: normal normal normal 12px/normal song, Verdana;"><td style="font: normal normal normal 12px/normal song, Verdana;"><div style="font: normal normal normal 12px/normal song, Verdana; line-height: 18px; margin-bottom: 5px; margin-left: 5px; margin-right: 5px; margin-top: 5px;"><code><span style="color: black;"><span style="color: #0000cc;">-</span> <span style="color: #0000cc;">(</span><span style="color: blue;">void</span><span style="color: #0000cc;">)</span> <span style="color: red;">test</span><span style="color: #0000cc;">:</span><span style="color: #0000cc;">(</span>NSNotification<span style="color: #0000cc;">*</span><span style="color: #0000cc;">)</span> notification<br style="font: normal normal normal 12px/normal song, Verdana;" /><span style="color: #0000cc;">{</span><br style="font: normal normal normal 12px/normal song, Verdana;" />searchFriendArrary <span style="color: #0000cc;">=</span> <span style="color: #0000cc;">[</span>notification object<span style="color: #0000cc;">]</span><span style="color: #0000cc;">;</span><span style="color: #ff9900;">//通過這個獲取到傳遞的對象</span><br style="font: normal normal normal 12px/normal song, Verdana;" /><span style="color: #0000cc;">}</span></span></code></div><div><code><span style="color: black;"><span style="color: #0000cc;"><br />
</span></span></code></div></td></tr>
</tbody></table><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-6938097535755120189?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-19583561242218043842011-02-15T19:45:00.000-08:002011-02-15T19:45:21.354-08:002011-02-15T19:45:21.354-08:00iPhone/Mac Objective-C 記憶體管理教程和原理剖析<span class="Apple-style-span" style="border-collapse: collapse; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 14px; line-height: 24px;"></span><br />
<div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">版權聲明</span></div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">此文版權歸作者</span>Vince Yuan (vince.yuan#gmail.com)<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">所有。歡迎非營利性轉載,轉載時必須包含原始鏈接</span><a href="http://vinceyuan.cnblogs.com/" style="color: #0070af; outline-color: initial; outline-style: none; outline-width: initial; text-decoration: none;" target="_blank"></a><a href="http://vinceyuan.cnblogs.com/" id="url_1" style="color: #0070af; outline-color: initial; outline-style: none; outline-width: initial; text-decoration: none;" target="_blank">http://vinceyuan.cnblogs.com/</a><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,且必須包含此版權聲明的完整內容。</span></div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"></div><div align="left" class="MsoNormal" style="margin-bottom: 0pt; margin-left: 0cm; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">版本</span><span lang="EN-US" style="outline-color: initial; outline-style: none; outline-width: initial;"><span style="font-family: Calibri; line-height: 1.5em; outline-color: initial; outline-style: none; outline-width: initial;"> 1.1 </span></span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">發表於</span><span lang="EN-US" style="outline-color: initial; outline-style: none; outline-width: initial;"><span style="font-family: Calibri; line-height: 1.5em; outline-color: initial; outline-style: none; outline-width: initial;">2010-03-08</span></span></div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">前言</span></div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">初學</span>objectice-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的朋友都有一個困惑,總覺得對</span>objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的內存管理機制琢磨不透,程序經常內存洩漏或莫名其妙的崩潰。我在這裡總結了自己對</span>objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">內存管理機制的研究成果和經驗,寫了這麼一個由淺入深的教程。希望對大家有所幫助,也歡迎大家一起探討。</span></div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div align="left" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">此文涉及的內存管理是針對於繼承於</span>NSObject<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的</span>Class<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">一</span> <span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">基本原理</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的內存管理機制與</span>.Net/Java<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">那種全自動的垃圾回收機制是不同的,它本質上還是</span>C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">語言中的手動管理方式,只不過稍微加了一些自動方法。</span></div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">1<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的對象生成於堆之上,生成之後,需要一個指針來指向它。</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj1 = [[ClassA alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">2<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的對象在使用完成之後不會自動銷毀,需要執行</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">來釋放空間(銷毀),否則內存洩露。</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 dealloc];</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> </span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">這帶來了一個問題。下面代碼中</span>obj2<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">是否需要調用</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">?</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj1 = [[ClassA alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj2 = obj1;</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 dealloc];</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj2 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">能夠執行這一行和下一行嗎?</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj2 dealloc];</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> </span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">不能,因為</span>obj1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">和</span>obj2<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">只是指針,它們指向同一個對象,</span>[obj1 dealloc]<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">已經銷毀這個對象了,不能再調用</span>[obj2 hello]<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">和</span>[obj2 dealloc]<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。</span>obj2<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">實際上是個無效指針。</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> </span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">如何避免無效指針?請看下一條。</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">3<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">采用了引用計數</span>(ref count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">或者</span>retain count)<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。對象的內部保存一個數字,表示被引用的次數。例如,某個對象被兩個指針所指向(引用)那麼它的</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">為</span>2<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。需要銷毀對象的時候,不直接調用</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,而是調用</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">會讓</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">減</span>1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,只有</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">等於</span>0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,系統才會調用</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">真正銷毀這個對象。</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj1 = [[ClassA alloc] init]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">對象生成時,</span>retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 release]; //release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">使</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">減</span>1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,</span>retain count = 0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">自動被調用</span>,<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">對象被銷毀</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">我們回頭看看剛剛那個無效指針的問題,把</span>dealloc<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">改成</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">解決了嗎?</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj1 = [[ClassA alloc] init]; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj2 = obj1; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj1 release]; //retain count = 0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,對象被銷毀</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj2 hello];</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">[obj2 release];</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> [obj1 release]</span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">之後,</span>obj2<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">依然是個無效指針。問題依然沒有解決。解決方法見下一條。</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">4<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">指針賦值時,</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">不會自動增加,需要手動</span>retain<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ClassA *obj1 = [[ClassA alloc] init]; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ClassA *obj2 = obj1; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="color: red; outline-color: initial; outline-style: none; outline-width: initial;">[obj2 retain]; //retain count = 2</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj1 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj1 release]; //retain count = 2 – 1 = 1</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj2 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj2 release]; //retain count = 0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,對象被銷毀</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">問題解決!注意,如果沒有調用</span>[obj2 release]<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,這個對象的</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">始終為</span>1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,不會被銷毀,內存洩露。</span>(1-4<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">可以參考附件中的示例程序</span>memman-no-pool.m)</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">這樣的確不會內存洩露,但似乎有點麻煩,有沒有簡單點的方法?見下一條。</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">5<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">中引入了</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">(自動釋放對象池),在遵守一些規則的情況下,可以自動釋放對象。(</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">依然不是</span>.Net/Java<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">那種全自動的垃圾回收機制)</span></div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">5.1<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">新生成的對象,只要調用</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">就行了,無需再調用</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">!</span></div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;">ClassA *obj1 = [[[ClassA alloc] init] autorelease]; //retain count = 1 <span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">但無需調用</span>release</div><div style="margin-bottom: 0pt; margin-left: 21pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">5.2<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">對於存在指針賦值的情況,代碼與前面類似。</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ClassA *obj1 = [[[ClassA alloc] init] autorelease]; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ClassA *obj2 = obj1; //retain count = 1</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="color: red; outline-color: initial; outline-style: none; outline-width: initial;">[obj2 retain]; //retain count = 2</span></div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj1 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">//<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">對於</span>obj1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,無需調用(實際上不能調用)</span>release</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj2 hello]; //<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">輸出</span>hello</div><div style="margin-bottom: 0pt; margin-left: 42pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[obj2 release]; //retain count = 2-1 = 1</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">細心的讀者肯定能發現這個對象沒有被銷毀,何時銷毀呢?誰去銷毀它?(可以參考附件中的示例程序</span>memman-with-pool.m<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">)請看下一條。</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 21pt;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">6<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">原理剖析。(其實很簡單的,一定要堅持看下去,否則還是不能理解</span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的內存管理機制。)</span></div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">6.1<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">不是天生的,需要手動創立。只不過在新建一個</span>iphone<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">項目時,</span>xcode<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">會自動幫你寫好。</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的真名是</span>NSAutoreleasePool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。</span></div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">6.2<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>NSAutoreleasePool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">內部包含一個數組(</span>NSMutableArray<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">),用來保存聲明為</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的所有對象。如果一個對象聲明為</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,系統所做的工作就是把這個對象加入到這個數組中去。</span></div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ClassA *obj1 = [[[ClassA alloc] init] autorelease]; //retain count = 1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,把此對象加入</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">中</span></div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">6.3<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>NSAutoreleasePool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">自身在銷毀的時候,會遍歷一遍這個數組,</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">數組中的每個成員。如果此時數組中成員的</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">為</span>1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,那麼</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">之後,</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">為</span>0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,對象正式被銷毀。如果此時數組中成員的</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">大於</span>1<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,那麼</span>release<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">之後,</span>retain count<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">大於</span>0<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,此對象依然沒有被銷毀,內存洩露。</span></div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -1cm;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">6.4<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">默認只有一個</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,通常類似於下面這個例子。</span></div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">int main (int argc, const char *argv[])</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">{</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 10.5pt;">NSAutoreleasePool *pool;</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 10.5pt;">pool = [[NSAutoreleasePool alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 10.5pt;">// do something</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 10.5pt;">[pool release];</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 10.5pt;">return (0);</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} // main</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;"></span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;"><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">所有標記為</span><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">autorelease</span><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">的對象都只有在這個</span><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">pool</span><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">銷毀時才被銷毀</span>。如果你有大量的對象標記為</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,這顯然不能很好的利用內存,在</span>iphone<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">這種內存受限的程序中是很容易造成內存不足的。例如:</span></div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">int main (int argc, const char *argv[])</div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">{</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">int i, j;</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">for (i = 0; i < 100; i++ )</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">{</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> for (j = 0; j < 100000; j++ )</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> [NSString stringWithFormat:@"1234567890"];//</span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">產生的對象是</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的。</span></div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">}</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[pool release];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">return (0);</div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} // main</div><div style="margin-bottom: 0pt; margin-left: 52.7pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">(可以參考附件中的示例程序</span>memman-many-objs-one-pool.m<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,運行時通過監控工具可以發現使用的內存在急劇增加,直到</span>pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">銷毀時才被釋放)你需要考慮下一條。</span></div><div style="margin-bottom: 0pt; margin-left: 49.6pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="margin-bottom: 0pt; margin-left: 21.25pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: -21.25pt;"><span style="outline-color: initial; outline-style: none; outline-width: initial;">7<span style="font: normal normal normal 7pt/normal 'Times New Roman'; outline-color: initial; outline-style: none; outline-width: initial;"> </span></span>Objective-C<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">程序中可以嵌套創建多個</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">。在需要大量創建局部變量的時候,可以創建內嵌的</span>autorelease pool<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">來及時釋放內存。<span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;"><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">(感謝網友</span><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">hhyytt</span><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">和</span><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">neogui</span><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">的提醒,某些情況下,系統會自動創建</span><span lang="EN-US" style="font-family: Calibri, sans-serif; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">autorelease pool, </span><span style="font-family: 宋体; font-size: 10.5pt; outline-color: initial; outline-style: none; outline-width: initial;">請參見第四章)</span></span></span></div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">int main (int argc, const char *argv[])</div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">{</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">int i, j;</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">for (i = 0; i < 100; i++ )</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">{</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> for (j = 0; j < 100000; j++ )</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="outline-color: initial; outline-style: none; outline-width: initial;"> [NSString stringWithFormat:@"1234567890"];//</span><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">產生的對象是</span>autorelease<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">的。</span></div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"> [loopPool release];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">}</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">[pool release];</div><div style="margin-bottom: 0pt; margin-left: 63pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">return (0);</div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">} // main</div><div style="margin-bottom: 0pt; margin-left: 52.5pt; margin-right: 0cm; margin-top: 0cm; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">(可以參考附件中的示例程序</span>memman-many-objs-many-pools.m<span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;">,佔用內存的變化極小)</span></div><div><span style="font-family: 宋体; outline-color: initial; outline-style: none; outline-width: initial;"><br />
</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-1958356124221804384?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-87566396087573111582011-02-15T18:51:00.000-08:002011-02-15T18:51:11.686-08:002011-02-15T18:51:11.686-08:00Objective C 教學!<a href="http://www.otierney.net/objective-c.html.zh-tw.big5">http://www.otierney.net/objective-c.html.zh-tw.big5</a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-8756639608757311158?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-24998825559756697432011-02-15T08:38:00.001-08:002011-02-15T08:44:18.543-08:002011-02-15T08:44:18.543-08:00iPhone,iPad Icon格式說明<a href="http://developer.apple.com/library/ios/#qa/qa2010/qa1686.html">http://developer.apple.com/library/ios/#qa/qa2010/qa1686.html</a><br />
<br />
<span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"></span><br />
<h2 style="border-bottom-color: rgb(80, 136, 197); border-bottom-style: solid; border-bottom-width: 1px; color: #3c4c6c; font-size: 20px; font-weight: normal; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 2em; padding-bottom: 2px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">iPhone-only Apps</h2><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Include the following in your application's Resources group in the Xcode project:</div><div class="smalltext" style="color: black; font-size: 10px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Table 1 : </strong>iPhone-only apps icon requirements.</div><table cellspacing="0" class="graybox" style="border-left-color: rgb(155, 179, 205); border-left-style: solid; border-left-width: 1px; border-top-color: rgb(155, 179, 205); border-top-style: solid; border-top-width: 1px; margin-bottom: 4em;"><tbody>
<tr><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Image Size (px)</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">File Name</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Used For</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Required Status</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Notes</th></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">512x512</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">iTunesArtwork</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Ad Hoc iTunes</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">File should be in png format, but name it without the .png extension</td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">57x57</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">App Store and Home screen on iPhone/iPod touch</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Required</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">114x114</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon@2x.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Home screen for iPhone 4 High Resolution</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">72x72</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-72.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Home screen for iPad compatibility</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">29x29</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight and Settings</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">50x50</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small-50.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight for iPad compatibility</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Recommended if you have a Settings bundle, otherwise optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">58x58</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small@2x.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight and Settings for iPhone 4 High Resolution</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Recommended if you have a Settings bundle, otherwise optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
</tbody></table><span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"></span><br />
<h2 style="border-bottom-color: rgb(80, 136, 197); border-bottom-style: solid; border-bottom-width: 1px; color: #3c4c6c; font-size: 20px; font-weight: normal; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 2em; padding-bottom: 2px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">iPad-only Apps</span></h2><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">Include the following in your application's Resources group in the Xcode project:</span></div><div class="smalltext" style="color: black; font-size: 10px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><strong>Table 2 : </strong>iPad-only apps icon requirements.</span></div><table cellspacing="0" class="graybox" style="border-left-color: rgb(155, 179, 205); border-left-style: solid; border-left-width: 1px; border-top-color: rgb(155, 179, 205); border-top-style: solid; border-top-width: 1px; margin-bottom: 4em;"><tbody>
<tr><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Image Size (px)</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">File Name</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Used For</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Required Status</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Notes</th></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">512x512</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">iTunesArtwork</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Ad Hoc iTunes</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">File should be in png format, but name it without the .png extension</td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">72x72</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-72.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">App Store and Home screen on iPad</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Required</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">50x50</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small-50.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight on iPad</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">29x29</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Settings on iPad</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Recommended if you have a Settings bundle, otherwise optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
</tbody></table><span class="Apple-style-span" style="font-family: 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><h2 style="border-bottom-color: rgb(80, 136, 197); border-bottom-style: solid; border-bottom-width: 1px; color: #3c4c6c; font-size: 20px; font-weight: normal; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 2em; padding-bottom: 2px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Universal Apps</h2><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Include the following in your application's Resources group in the Xcode project:</div><div class="smalltext" style="color: black; font-size: 10px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Table 3 : </strong>Universal apps icon requirements.</div><table cellspacing="0" class="graybox" style="border-left-color: rgb(155, 179, 205); border-left-style: solid; border-left-width: 1px; border-top-color: rgb(155, 179, 205); border-top-style: solid; border-top-width: 1px; margin-bottom: 4em;"><tbody>
<tr><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Image Size (px)</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">File Name</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Used For</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Required Status</th><th style="background-attachment: initial; background-clip: initial; background-color: #93a5bb; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; color: white; font-size: 13px; font-weight: normal; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.333em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.333em; text-align: left; vertical-align: top;">Notes</th></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">512x512</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">iTunesArtwork</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Ad Hoc iTunes</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">File should be in png format, but name it without the .png extension</td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">57x57</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">App Store and the Home screen on iPhone/iPod touch</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Required</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">114x114</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon@2x.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Home screen for iPhone 4 High Resolution</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">72x72</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-72.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">App Store and Home screen on iPad</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Required</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">29x29</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Settings on iPad and iPhone, and Spotlight on iPhone</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Recommended if you have a Settings bundle, otherwise optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">50x50</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small-50.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight on iPad</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
<tr><td scope="row" style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">58x58</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Icon-Small@2x.png</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Spotlight and Settings for iPhone 4 High Resolution</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;">Recommended if you have a Settings bundle, otherwise optional but recommended</td><td style="border-bottom-color: rgb(155, 179, 205); border-bottom-style: solid; border-bottom-width: 1px; border-right-color: rgb(155, 179, 205); border-right-style: solid; border-right-width: 1px; font-size: 13px; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Verdana, Arial, Helvetica, sans-serif; padding-bottom: 0.667em; padding-left: 0.667em; padding-right: 0.667em; padding-top: 0.667em; text-align: left; vertical-align: middle;"><None></td></tr>
</tbody></table><h2 style="border-bottom-color: rgb(80, 136, 197); border-bottom-style: solid; border-bottom-width: 1px; color: #3c4c6c; font-size: 20px; font-weight: normal; margin-bottom: 1em; margin-left: 0px; margin-right: 0px; margin-top: 2em; padding-bottom: 2px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Add Icon files in Info.plist</h2><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">To add the <code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Icon files</code> entry you will need to manually edit your <code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Info.plist</code>.</div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Open your <code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Info.plist</code> in Xcode, and locate the "<code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Icon file</code>" entry. Click on the plus (+) button at the end of the entry to make a new key entry. as shown in <a href="http://developer.apple.com/library/ios/qa/qa2010/qa1686.html#PLUSBUTTON">Figure 2</a>.</div><a href="" name="PLUSBUTTON"></a><div class="caption" style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Figure 2: </strong>Add a new entry under "Icon file" key</div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><img alt="Figure 2, Add a new entry under "Icon file" key" height="446" src="http://developer.apple.com/library/ios/qa/qa2010/images/qa1686_1.png" width="640" /></div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Then, type "<code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Icon files</code>" in the key column (notice the "<code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">s</code>" added), or choose "<code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Icon files</code>" from the drop down list, as shown in <a href="http://developer.apple.com/library/ios/qa/qa2010/qa1686.html#ADDICONFILESKEY">Figure 3</a>.</div><a href="" name="ADDICONFILESKEY"></a><div class="caption" style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Figure 3: </strong>Add "Icon files" key in Info.plist</div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><img alt="Figure 3, Add "Icon files" key in Info.plist" height="310" src="http://developer.apple.com/library/ios/qa/qa2010/images/qa1686_2.png" width="575" /></div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Next, turn down the disclosure triangle on "<code style="color: #666666; font-family: Courier, monospace; font-size: 17px;">Icon files</code>" and add the entries for the icons for your application, as shown in <a href="http://developer.apple.com/library/ios/qa/qa2010/qa1686.html#IPHONEADDITEMS">Figure 4</a> and <a href="http://developer.apple.com/library/ios/qa/qa2010/qa1686.html#IPADADDITEMS">Figure 5</a>:</div><a href="" name="IPHONEADDITEMS"></a><div class="caption" style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Figure 4: </strong>Add icon file entries for iPhone-only or Universal apps.</div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><img alt="Figure 4, Add icon file entries for iPhone-only or Universal apps." height="553" src="http://developer.apple.com/library/ios/qa/qa2010/images/qa1686_3.png" width="640" /></div><a href="" name="IPADADDITEMS"></a><div class="caption" style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><strong>Figure 5: </strong>Add entries for iPad icon files.</div><div style="color: black; font: normal normal normal 90%/normal 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; line-height: 19px; margin-bottom: 0.833em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><img alt="Figure 5, Add entries for iPad icon files." height="512" src="http://developer.apple.com/library/ios/qa/qa2010/images/qa1686_4.png" width="640" /></div></span><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-2499882555975669743?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-62398946835877531572011-02-15T06:35:00.001-08:002011-02-15T06:35:46.562-08:002011-02-15T06:35:46.562-08:00iPhone Web App 參考網頁<a href="http://developer.apple.com/library/safari/#referencelibrary/GettingStarted/GS_WebApp/">http://developer.apple.com/library/safari/#referencelibrary/GettingStarted/GS_WebApp/</a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-6239894683587753157?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-50464848911689458922011-02-15T02:00:00.001-08:002011-02-15T06:46:05.535-08:002011-02-15T06:46:05.535-08:00iPhone各類Code筆記(未分類)<span class="Apple-style-span" style="font-family: 'Comic Sans MS', 宋体, Arial, sans-serif; font-size: 13px; line-height: 19px;"></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;">1. 隨機數:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">srandom(time(NULL)); </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">隨機數種子</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
id d </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> random(); </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 隨機數</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 2. 視頻播放:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> MPMoviePlayerController </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">moviePlayer;<br />
moviePlayer </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[MPMoviePlayerController alloc]<br />
initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Movie</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ofType:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">m4v</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]]];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">初始化視頻播放器對象,並傳入被播放文件的地址</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> moviePlayer.movieControlMode </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> MPMovieControlModeDefault;<br />
[moviePlayer play];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">此處有內存溢出</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 3. <span style="color: #444444; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 18px;"> 啟動界面顯示:</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #444444; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 18px;">iPhone軟件啟動後的第一屏圖片是非常重要的往往就是loading載入中的意思。設置它說來也簡單,但是卻無比重要</span></div><span style="color: #444444; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 10px; line-height: normal;"></span><br />
<div style="font-size: 1.2em; line-height: 1.5em; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 0px; text-align: justify; text-indent: 0px;"><span style="color: #444444; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 10px; line-height: normal;">只需要在resource裡面將你希望設置的圖片更名為Default.png,這個圖片就可以成為iPhone載入的缺省圖片</span></div><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 4. iPhone的系統目錄:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"></span></div><span style="color: #ff6600;"></span><br />
<div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: #ff6600;"><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">得到Document目錄:</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSArray </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">paths </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);<br />
NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">documentsDirectory </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [paths objectAtIndex:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">得到temp臨時目錄:</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">tempPath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSTemporaryDirectory();<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">得到目錄上的文件地址:</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">文件地址 </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [目錄地址 stringByAppendingPathComponent:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">文件名.擴展名</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span></span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"><br />
</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"> <span style="color: black; font-size: 13px; line-height: 1.5;">5. 狀態欄顯示Indicator:</span></span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"><span style="color: black; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: small;"><span style="border-collapse: collapse; font-size: 13px; line-height: 14px;"></span></span></span></div><span style="color: #ff6600;"><span style="color: black; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: small;"><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[UIApplication sharedApplication].networkActivityIndicatorVisible </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES; </span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 6.app Icon顯示數字:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)applicationDidEnterBackground:(UIApplication </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)application{<br />
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">5</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
}</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div> 7.sqlite保存地址:</span></span><br />
<div><span style="color: #ff6600;"><span style="color: black; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: small;"></span></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"><span style="color: black; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: small;"><br />
</span></span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"><br />
</span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span class="Apple-style-span" style="color: #ff6600;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSArray </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">paths </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);</span></span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_6d10c0c5-09b3-451a-8ea8-bb8a00d77e83" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="color: #ff6600;"><span class="Apple-style-span" style="line-height: 1.5;"> NSString </span></span></span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">thePath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [paths objectAtIndex:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">filePath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [thePath stringByAppendingPathComponent:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">kilonet1.sqlite</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
<br />
NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">dbPath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[[NSBundle mainBundle] resourcePath]<br />
stringByAppendingPathComponent:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">kilonet2.sqlite</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]; </span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #ff6600;"><br />
</span></div><span style="color: #ff6600;"><span style="color: black; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: small; line-height: 1.5;"> 8.Application退出:exit(0);</span></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 9. AlertView,ActionSheet的cancelButton點擊事件:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) actionSheet :(UIActionSheet </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {</span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_b4da12a6-7e11-4fac-948d-8de1a07ba94d" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="line-height: 1.5;"> NSLog(</span></span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">cancel actionSheet........</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">當用戶按下cancel按鈕</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">( buttonIndex </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">==</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [actionSheet cancelButtonIndex]) {<br />
exit(</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
}</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">當用戶按下destructive按鈕</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> if( buttonIndex == [actionSheet destructiveButtonIndex]) {</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> DoSomething here.</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> }</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">}<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)alertView:(UIAlertView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">cancel alertView........</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (buttonIndex </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">==</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [alertView cancelButtonIndex]) {<br />
exit(</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
}<br />
}</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 10.給Window設置全局的背景圖片:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">window.backgroundColor </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [UIColor colorWithPatternImage:[UIImage imageNamed:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">coolblack.png</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 11. UITextField文本框顯示及對鍵盤的控制:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">#pragma</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> mark -</span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_6c54a0e8-27ba-4834-8f91-d4d97f965a05" style="display: block;"><div><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">#pragma</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> mark UITextFieldDelegate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">控制鍵盤跳轉</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (BOOL)textFieldShouldReturn:(UITextField </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)textField {<br />
<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (textField </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">==</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> _txtAccount) {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ([_txtAccount.text length]</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">==</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NO;<br />
}<br />
[_txtPassword becomeFirstResponder];<br />
} </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (textField </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">==</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> _txtPassword) {<br />
[_txtPassword resignFirstResponder];<br />
}<br />
<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES;<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">輸入框背景更換</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(BOOL) textFieldShouldBeginEditing:(UITextField </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)textField{<br />
<br />
[textField setBackground:[UIImage imageNamed:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">ctext_field_02.png</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]];<br />
<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES;<br />
}<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) textFieldDidEndEditing:(UITextField </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)textField{<br />
[textField setBackground:[UIImage imageNamed:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">ctext_field_01.png</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]];<br />
}</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 12.UITextField文本框前面空白寬度設置以及後面組合按鈕設置:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">給文本輸入框後面加入空白</span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_6076555b-3ee2-4f43-8500-3224a0334209" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> _txtAccount.rightView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> _btnDropDown;<br />
_txtAccount.rightViewMode </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> UITextFieldViewModeAlways;<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">給文本輸入框前面加入空白</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> CGRect frame </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [_txtAccount frame];<br />
frame.size.width </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">5</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
UIView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">leftview </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIView alloc] initWithFrame:frame];<br />
_txtAccount.leftViewMode </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> UITextFieldViewModeAlways;<br />
_txtAccount.leftView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> leftview;</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 13. UIScrollView 設置滑動不超出本身范圍:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #558186; font-family: Menlo; font-size: 11px; line-height: normal;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [</span>fcScrollView<span style="color: black; font-size: 13px; line-height: 1.5;"> </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">setBounces</span><span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #b414a1; font-size: 13px; line-height: 1.5;">NO</span><span style="color: black; font-size: 13px; line-height: 1.5;">];</span></span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 14. 遍歷View裡面所有的Subview:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSLog(@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">subviews count=%d</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,[self.view.subviews count]);</span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_84636021-09be-46ee-becf-7db4710e04fd" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="line-height: 1.5;"> </span></span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ([self.view.subviews count] </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">></span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">for</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (UIView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">curView </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> self.view.subviews) {<br />
NSLog(@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">view.subviews=%@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, [NSString stringWithUTF8String:object_getClassName(curView)]);<br />
}<br />
}</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 14. 在drawRect裡畫文字:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: Menlo; font-size: 11px; line-height: normal;"> <span style="color: #7031a8; font-size: 13px; line-height: 1.5;">UIFont</span> * f = [<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">UIFont</span> <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">systemFontOfSize</span>:<span style="color: #3900d5; font-size: 13px; line-height: 1.5;">20</span>]; </span></div><div style="color: #3f0b80; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [[</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">UIColor</span><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>darkGrayColor<span style="color: black; font-size: 13px; line-height: 1.5;">] </span>set<span style="color: black; font-size: 13px; line-height: 1.5;">]; </span></div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> <span style="color: #7031a8; font-size: 13px; line-height: 1.5;">NSString</span> * text = <span style="color: #c82a25; font-size: 13px; line-height: 1.5;">@"hi \nKiloNet"</span>; </div><div style="color: #3f0b80; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [text </span>drawAtPoint<span style="color: black; font-size: 13px; line-height: 1.5;">:</span>CGPointMake<span style="color: black; font-size: 13px; line-height: 1.5;">(</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">center</span><span style="color: black; font-size: 13px; line-height: 1.5;">.</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">x</span><span style="color: black; font-size: 13px; line-height: 1.5;">,</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">center</span><span style="color: black; font-size: 13px; line-height: 1.5;">.</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">y</span><span style="color: black; font-size: 13px; line-height: 1.5;">) </span>withFont<span style="color: black; font-size: 13px; line-height: 1.5;">:f];</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 15. NSArray查找是否存在對象時用<span style="color: #3f0b80; font-family: Menlo; font-size: 11px; line-height: normal;">indexOfObject,</span>如果不存在則返回為<span style="color: #3f0b80; font-family: Menlo; font-size: 11px; line-height: normal;">NSNotFound</span>.</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 16. NString與NSArray之間相互轉換:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">array </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">string</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> componentsSeparatedByString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">string</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[array valueForKey:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">description</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">] componentsJoinedByString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 17. TabController隨意切換tab bar:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="font-family: monospace; font-size: 13px; line-height: 1.5; white-space: pre;"> [self.tabBarController setSelectedIndex:tabIndex];</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="font-family: monospace; font-size: 13px; line-height: 1.5; white-space: pre;"></span><span style="font-family: monospace; font-size: 13px; line-height: 1.5; white-space: pre;"> 或者 self.tabBarController.selectedIndex = tabIndex;</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="font-family: monospace; font-size: 13px; line-height: 1.5; white-space: pre;"></span><span style="font-family: monospace; font-size: 13px; line-height: 1.5; white-space: pre;"> 或者實現下面的delegate來撲捉tab bar的事件: </span></div><pre style="margin-bottom: 0px; margin-top: 0px;"><span style="font-family: verdana, 'courier new'; font-size: 13px; line-height: 1.5; white-space: normal;"><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(BOOL) tabBarController:(UITabBarController </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)tabBarController shouldSelectViewController:(UIViewController </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)viewController {
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ([viewController.tabBarItem.title isEqualToString: NSLocalizedString(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Logout</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,nil)]) {
[self showLogout];
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NO;
}
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES;
}</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"></div></span></pre><pre style="margin-bottom: 0px; margin-top: 0px;"><span style="font-family: verdana, 'courier new'; font-size: 13px; line-height: 1.5; white-space: normal;"> 18. 自定義View之間切換動畫:</span></pre></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_2c234613-184e-41af-9b15-e7162b2d0fbe" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) pushController: (UIViewController</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) controller<br />
withTransition: (UIViewAnimationTransition) transition<br />
{<br />
[UIView beginAnimations:nil context:NULL];<br />
[self pushViewController:controller animated:NO];<br />
[UIView setAnimationDuration:.</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">5</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
[UIView setAnimationBeginsFromCurrentState:YES]; <br />
[UIView setAnimationTransition:transition forView:self.view cache:YES];<br />
[UIView commitAnimations];<br />
}</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 或者:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_0e2e3836-b38c-42f1-82ad-72e28e36a5d0" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">CATransition </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">transition </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [CATransition animation];<br />
transition.duration </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> kAnimationDuration;<br />
transition.timingFunction </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];<br />
transition.type </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> kCATransitionPush;<br />
transition.subtype </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> kCATransitionFromTop;<br />
transitioning </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES;<br />
transition.</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">delegate</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> self;<br />
[self.navigationController.view.layer addAnimation:transition forKey:nil];<br />
<br />
self.navigationController.navigationBarHidden </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NO;<br />
[self.navigationController pushViewController:tableViewController animated:YES];</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 19. UIWebView加載時白色顯示問題解決以及字體統一設置:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="font-family: Menlo; font-size: 11px; line-height: normal;"> uiWebView.<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">opaque</span> = <span style="color: #b414a1; font-size: 13px; line-height: 1.5;">NO</span>;</span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 20.計算字符串長度:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #3f0b80; font-family: Menlo; font-size: 11px; line-height: normal;"><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">CGFloat</span><span style="color: black; font-size: 13px; line-height: 1.5;"> w = [title </span>sizeWithFont<span style="color: black; font-size: 13px; line-height: 1.5;">:[</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">UIFont</span><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>fontWithName<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #c82a25; font-size: 13px; line-height: 1.5;">@"Arial"</span><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>size<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #3900d5; font-size: 13px; line-height: 1.5;">18</span><span style="color: black; font-size: 13px; line-height: 1.5;">]].</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">width</span><span style="color: black; font-size: 13px; line-height: 1.5;">;</span></span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 21. iTunesLink should be your applications link</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;">NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=xxxxxx&mt=8";</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;">[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];</div><div><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 22.時間轉換NSString & NSDate:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: Menlo; font-size: 11px; line-height: normal;">-(<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">NSDate</span> *)NSStringDateToNSDate:(<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">NSString</span> *)string { </span></div><div style="color: #7031a8; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>NSDateFormatter<span style="color: black; font-size: 13px; line-height: 1.5;"> *formatter = [[</span>NSDateFormatter<span style="color: black; font-size: 13px; line-height: 1.5;"> </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">alloc</span><span style="color: black; font-size: 13px; line-height: 1.5;">] </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">init</span><span style="color: black; font-size: 13px; line-height: 1.5;">];</span></div><div style="color: #3f0b80; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [formatter </span>setTimeZone<span style="color: black; font-size: 13px; line-height: 1.5;">:[</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">NSTimeZone</span><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>timeZoneWithAbbreviation<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #c82a25; font-size: 13px; line-height: 1.5;">@"UTC"</span><span style="color: black; font-size: 13px; line-height: 1.5;">]];</span></div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> [formatter <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">setDateFormat</span>:<span style="color: #c82a25; font-size: 13px; line-height: 1.5;">@"yyyy-MM-dd"</span>];</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> <span style="color: #7031a8; font-size: 13px; line-height: 1.5;">NSDate</span> *date = [formatter <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">dateFromString</span>:string];</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> [formatter <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">release</span>];</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> <span style="color: #b414a1; font-size: 13px; line-height: 1.5;">return</span> date;</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">}</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="border-collapse: collapse; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 13px; line-height: 18px; white-space: pre;"><span class="typ" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">year </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">myDate descriptionWithCalendarFormat</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:@</span><span class="str" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: maroon; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"%Y"</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> timeZone</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="kwd" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: darkblue; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">nil</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> locale</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="kwd" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: darkblue; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">nil</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span></span></div><span style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 18px;"></span><br />
<pre class="prettyprint" style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><span style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 18px;"><code style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">or</span></code></span></pre><pre class="prettyprint" style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><span style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 18px;"><code style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 1.5; white-space: normal;"><pre class="prettyprint" style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-color: #eeeeee; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="typ" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSDateFormatter</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">formatter </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[[</span><span class="typ" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSDateFormatter</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> alloc</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">]</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> init</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">formatter setDateFormat</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:@</span><span class="str" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: maroon; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"yyyy"</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
</span><span class="com" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: grey; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">//Optionally for time zone converstions</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">formatter setTimeZone</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:[</span><span class="typ" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSTimeZone</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> timeZoneWithName</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:@</span><span class="str" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: maroon; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"..."</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">]];</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
</span><span class="typ" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">stringFromDate </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">formatter stringFromDate</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">myNSDateInstance</span><span class="pun" style="background-color: transparent; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span></code></pre></span></span></code></span></pre><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 22。 模擬器的文件位置</div><span style="border-collapse: collapse; color: #444444; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 12px; line-height: normal;"></span><br />
<table cellpadding="0" cellspacing="0" style="border-collapse: collapse; empty-cells: show; line-height: normal; margin-left: 1px; table-layout: fixed; width: 824px; word-wrap: break-word;"><tbody style="line-height: normal; word-wrap: break-word;">
<tr style="line-height: normal; word-wrap: break-word;"><td class="t_msgfont" id="postmessage_218695" style="color: #444444; display: table-cell; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font: normal normal normal 14px/1.6em Verdana, Helvetica, Arial, sans-serif; visibility: visible; word-wrap: break-word;">其中#username#表示當前用戶名:<br />
/Users/#username#/Library/Application Support/iPhone Simulator/User/Applications/</td></tr>
</tbody></table><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 23.<span style="color: #242020; font-family: 'Microsoft YaHei', Helvetica, Arial; font-size: 13px; line-height: 28px;">在使用UISearchBar時,將背景色設定為clearColor,或者將translucent設為YES,都不能使背景透明,經過一番研究,發現了一種超級簡單和實用的方法:</span></div><span style="color: #242020; font-family: 'Microsoft YaHei', Helvetica, Arial; font-size: 13px; line-height: 28px;"></span><br />
<div class="codecolorer-container objc mac-classic" style="background-color: white; border-left-color: rgb(159, 159, 159); color: black; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; margin-bottom: 10px; overflow-x: auto; overflow-y: auto; text-align: left; white-space: nowrap;"><table cellpadding="0" cellspacing="0" style="border-collapse: collapse; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace;"><tbody style="font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace;">
<tr style="font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace;"><td class="line-numbers" style="background-color: #eeeeee; color: #888888; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; text-align: right;"><div style="font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; width: 23px;">1</div></td><td style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;"><div class="objc codecolorer" style="background-color: white; color: black; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; text-align: left; white-space: nowrap;"><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span>searchbar.subviews objectAtIndex<span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">:</span>0<span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span>removeFromSuperview<span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span>;</div></td></tr>
</tbody></table></div><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #242020; font-family: 'Microsoft YaHei', Helvetica, Arial; font-size: 13px; line-height: 28px;">背景完全消除了,只剩下搜索框本身了。</span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 24. 圖像與緩存 :</div><span style="border-collapse: collapse; font-family: Monaco, 'Lucida Console', monospace; font-size: 13px; line-height: 18px; white-space: nowrap;">UIImageView <span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">*</span>wallpaper <span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">=</span> <span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span>UIImageView alloc<span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span> initWithImage<span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">:</span></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="border-collapse: collapse; font-family: Monaco, 'Lucida Console', monospace; font-size: 13px; line-height: 18px; white-space: nowrap;"> <span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span>UIImage imageNamed<span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">:</span><span class="co3" style="color: #0066ff; font-size: 13px; font: italic normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">@</span><span class="st0" style="color: #036a07; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">"icon.png"</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span>;</span> //<strong> 會緩存圖片</strong></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><span style="border-collapse: collapse; font-family: Monaco, 'Lucida Console', monospace; font-size: 13px; line-height: 18px; white-space: nowrap;">UIImageView <span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">*</span>wallpaper <span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">=</span> <span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span>UIImageView alloc<span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span> initWithImage<span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">:</span></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="border-collapse: collapse; font-family: Monaco, 'Lucida Console', monospace; font-size: 13px; line-height: 18px; white-space: nowrap;"> <span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">[</span>UIImage <span class="sy0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">imageWithContentsOfFile:</span><span class="co3" style="color: #0066ff; font-size: 13px; font: italic normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">@</span><span class="st0" style="color: #036a07; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">"icon.png"</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span><span class="br0" style="color: black; font-size: 13px; font: normal normal normal 13px/1.4em Monaco, 'Lucida Console', monospace; line-height: 1.5;">]</span>;</span> // <strong>不會緩存圖片 </strong></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 25. iphone-常用的對視圖圖層(layer)的操作<br />
<br />
對圖層的操作:<br />
<br />
(1.給圖層添加背景圖片:<br />
myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage;<br />
<br />
(2.將圖層的邊框設置為圓腳<br />
myWebView.layer.cornerRadius = 8;<br />
myWebView.layer.masksToBounds = YES;<br />
<br />
(3.給圖層添加一個有色邊框<br />
myWebView.layer.borderWidth = 5;<br />
myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 26. <span style="color: #7031a8; font-family: Menlo; font-size: 11px; line-height: normal;">UIPopoverController 使用</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">-(<span style="color: #b414a1; font-size: 13px; line-height: 1.5;">void</span>) onSetting:(<span style="color: #b414a1; font-size: 13px; line-height: 1.5;">id</span>) sender {</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px; text-indent: 0px;"><br />
</div><div style="color: #558186; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>SplitBaseController<span style="color: black; font-size: 13px; line-height: 1.5;"> *detail = [[</span>SettingServerController<span style="color: black; font-size: 13px; line-height: 1.5;"> </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">alloc</span><span style="color: black; font-size: 13px; line-height: 1.5;">] </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">init</span><span style="color: black; font-size: 13px; line-height: 1.5;">];</span></div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px; text-indent: 0px;"> </div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> <span style="color: #7031a8; font-size: 13px; line-height: 1.5;">CGRect</span> frame = [(<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">UIView</span> *)sender <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">frame</span>];</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> frame.<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">origin</span>.<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">y</span> = <span style="color: #3900d5; font-size: 13px; line-height: 1.5;">0</span>;</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px; text-indent: 0px;"> </div><div style="color: #7031a8; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>UIPopoverController<span style="color: black; font-size: 13px; line-height: 1.5;"> *popwin = [[</span>UIPopoverController<span style="color: black; font-size: 13px; line-height: 1.5;"> </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">alloc</span><span style="color: black; font-size: 13px; line-height: 1.5;">] </span><span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">initWithContentViewController</span><span style="color: black; font-size: 13px; line-height: 1.5;">:detail];</span></div><div style="color: #3f0b80; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [popwin </span>setPopoverContentSize<span style="color: black; font-size: 13px; line-height: 1.5;">:</span>CGSizeMake<span style="color: black; font-size: 13px; line-height: 1.5;">(</span><span style="color: #3900d5; font-size: 13px; line-height: 1.5;">400</span><span style="color: black; font-size: 13px; line-height: 1.5;">, </span><span style="color: #3900d5; font-size: 13px; line-height: 1.5;">300</span><span style="color: black; font-size: 13px; line-height: 1.5;">) </span>animated<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #b414a1; font-size: 13px; line-height: 1.5;">YES</span><span style="color: black; font-size: 13px; line-height: 1.5;">];</span></div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> popwin.<span style="color: #7031a8; font-size: 13px; line-height: 1.5;">delegate</span> = <span style="color: #b414a1; font-size: 13px; line-height: 1.5;">self</span>;</div><div style="color: #3f0b80; font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="color: black; font-size: 13px; line-height: 1.5;"> [popwin </span>presentPopoverFromRect<span style="color: black; font-size: 13px; line-height: 1.5;">: frame </span>inView<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #b414a1; font-size: 13px; line-height: 1.5;">self</span><span style="color: black; font-size: 13px; line-height: 1.5;">.</span><span style="color: #7031a8; font-size: 13px; line-height: 1.5;">view</span><span style="color: black; font-size: 13px; line-height: 1.5;"> </span>permittedArrowDirections<span style="color: black; font-size: 13px; line-height: 1.5;">:</span>UIPopoverArrowDirectionAny<span style="color: black; font-size: 13px; line-height: 1.5;"> </span>animated<span style="color: black; font-size: 13px; line-height: 1.5;">:</span><span style="color: #b414a1; font-size: 13px; line-height: 1.5;">YES</span><span style="color: black; font-size: 13px; line-height: 1.5;">];</span></div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; font: normal normal normal 11px/normal Menlo; line-height: 1.4; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"> [detail <span style="color: #3f0b80; font-size: 13px; line-height: 1.5;">release</span>];</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="font-family: Menlo; font-size: 11px; line-height: normal;">}</span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="color: #cc6618; font-size: 13px; font: normal normal normal 20px/normal Times; line-height: 24px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="font-size: 13px; font: normal normal normal 20px/normal STSong; line-height: 1.5;"> 27.在</span>UINavigationBar<span style="font-size: 13px; font: normal normal normal 20px/normal STSong; line-height: 1.5;">中添加左箭頭返回按鈕</span></div><div style="font-size: 13px; font: normal normal normal 10px/normal Tahoma; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 12px; text-align: right; text-indent: 0px;"><br />
</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal 'Heiti SC Light'; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">在<span style="font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 1.5;">iPhone</span>裡面最討厭的控件之一就是<span style="font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 1.5;"> UINavigationBar</span>了。這個控件樣式修改不方便,連添加按鈕也特別麻煩。下面的例子是如何手動添加帶箭頭的按鈕:</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 14px; text-indent: 0px;"><br />
</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">UINavigationItem *item = [navBar.items objectAtIndex:0];</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">UINavigationItem *back = [[UINavigationItem alloc] initWithTitle:@"Back"];</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">NSArray *items = [[NSArray alloc] initWithObjects:back,item,nil];</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">[navBar setItems:items];</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 14px; text-indent: 0px;"><br />
</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">- (BOOL)navigationBar:(UINavigationBar *)navigationBar</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">shouldPopItem:(UINavigationItem *)item{</div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal 'Heiti SC Light'; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;"><span style="font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 1.5;">//</span>在此處添加點擊<span style="font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 1.5;">back</span>按鈕之後的操作代碼<span style="font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 1.5;"> </span></div><div style="color: #666666; font-size: 13px; font: normal normal normal 12px/normal Arial; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">return NO;</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="color: #666666; font-family: Arial; font-size: 12px; line-height: normal;">}</span> </div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-5046484891168945892?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0tag:blogger.com,1999:blog-1399164727595192864.post-72732181683094076712011-02-15T01:50:00.001-08:002011-02-15T01:53:58.594-08:002011-02-15T01:53:58.594-08:00iPhone代碼片段收集(持續更新)<span class="Apple-style-span" style="font-family: 'Comic Sans MS', 宋体, Arial, sans-serif; font-size: 13px; line-height: 19px;"></span><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 1. stringWithFormat 用法:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSString stringWithFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Hight: %d°%@ Low: %d°%@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, [Temp],</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">C</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,[lTemp],</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">C</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> NSString to NSData:</div><span style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 18px;"></span><br />
<pre class="prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><span style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 18px;"><code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="typ" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> str</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">@</span><span class="str" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"kilonet"</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
</span></code></span></pre><br />
<div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><span style="border-collapse: collapse; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 13px; line-height: 18px; white-space: pre;"><span class="typ" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> NSData</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> data</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=[</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">str dataUsingEncoding</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSUTF8StringEncoding</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; line-height: 1.5; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span></span> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 2. NSDate 用法:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;"> NSDate </span></span><span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;">*</span></span><span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;">today;</span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSDate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">tomorrow;<br />
today </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSDate date];<br />
tomorrow </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSDate dateWithTimeInterval:(i</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">24</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">60</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">60</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) sinceDate:today]; </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">可能有更好的</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> Date format用法:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-size: 13px; line-height: 1.5;">(NSString </span><span style="color: black; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-size: 13px; line-height: 1.5;">) getDay:(NSDate </span><span style="color: black; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-size: 13px; line-height: 1.5;">) d {</span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">s ;<br />
NSDateFormatter </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">format </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSDateFormatter alloc] init];<br />
[format setDateFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">YYYY/MM/dd hh:mm:ss</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
s </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [format stringFromDate:d];<br />
[format release];<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> s;<br />
}</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 各地時區獲取:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSDate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">nowDate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSDate </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">new</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span><br />
<div class="cnblogs_code_hide" id="cnblogs_code_open_c29eebc7-c3c4-4770-95dd-934601828aa5" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px;"><span class="Apple-style-span" style="line-height: 1.5;"> NSDateFormatter </span></span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">formatter </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSDateFormatter alloc] init];<br />
[formatter setDateFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">yyyy/MM/dd HH:mm:ss</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 根據時區名字獲取當前時間,如果該時區不存在,默認獲取系統當前時區的時間<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Europe/Andorra"]; <br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [formatter setTimeZone:timeZone];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">獲取所有的時區名字</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSArray </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">array </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSTimeZone knownTimeZoneNames];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSLog(@"array:%@",array);<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">for循環<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> for(int i=0;i<[array count];i++)<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> {<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:[array objectAtIndex:i]];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [formatter setTimeZone:timeZone];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSString *locationTime = [formatter stringFromDate:nowDate];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSLog(@"時區名字:%@ : 時區當前時間: %@",[array objectAtIndex:i],locationTime);<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSLog(@"timezone name is:%@",[array objectAtIndex:i]);<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> } <br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">快速枚舉法</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">for</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">timeZoneName </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> array){<br />
[formatter setTimeZone:[NSTimeZone timeZoneWithName:timeZoneName]];<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">%@,%@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,timeZoneName,[formatter stringFromDate:nowDate]);<br />
}<br />
<br />
[formatter release];<br />
[nowDate release];</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 獲取毫秒時間:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_4895dd7c-66bb-498f-9854-2661505f0fef" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSDateFormatter </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">dateFormatter </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSDateFormatter alloc] init];<br />
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];<br />
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[dateFormatter setDateFormat:@"hh:mm:ss"]</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [dateFormatter setDateFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">yyyy-MM-dd HH:mm:ss.SSS</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Date%@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, [dateFormatter stringFromDate:[NSDate date]]);<br />
[dateFormatter release];</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 3. <span style="color: #7031a8; font-family: Menlo; font-size: 11px; line-height: normal;">NSCalendar用法:</span></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-size: 13px; line-height: 1.5;">(NSString </span><span style="color: black; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-size: 13px; line-height: 1.5;">) getWeek:(NSDate </span><span style="color: black; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-size: 13px; line-height: 1.5;">) d {</span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> <br />
NSCalendar </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">calendar </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];<br />
unsigned units </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSYearCalendarUnit </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">|</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSMonthCalendarUnit </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">|</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSDayCalendarUnit </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">|</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSWeekdayCalendarUnit;<br />
NSDateComponents </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">components </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [calendar components:units fromDate:d];<br />
[calendar release];<br />
<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">switch</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ([components weekday]) {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">2</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Monday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">3</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Tuesday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">4</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Wednesday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">5</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Thursday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">6</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Friday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">7</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Saturday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">case</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">1</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Sunday</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">default</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">No Week</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">break</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
}<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 用components,我們可以讀取其他更多的數據。</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> <br />
}</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 4. 用Get方式讀取網絡數據:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 將網絡數讀取為字符串</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) getDataByURL:(NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) url {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] encoding:NSUTF8StringEncoding];<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">讀取網絡圖片</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (UIImage </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) getImageByURL:(NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) url {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];<br />
}<br />
</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 5. 多線程NSThread用法 :</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[NSThread detachNewThreadSelector:@selector(scheduleTask) toTarget:self withObject:nil];<br />
<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) scheduleTask {<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">create a pool </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSAutoreleasePool </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">pool </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSAutoreleasePool alloc] init];<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">release the pool;</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [pool release];<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">如果有參數,則這麼使用:</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[NSThread detachNewThreadSelector:@selector(scheduleTask:) toTarget:self withObject:[NSDate date]];<br />
<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) scheduleTask:(NSDate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) mdate {<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">create a pool </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSAutoreleasePool </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">pool </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSAutoreleasePool alloc] init];<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">release the pool;</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [pool release];<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">注意selector裡有冒號。</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-size: 13px; line-height: 1.5;">在線程裡運行主線程裡的方法 </span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [self performSelectorOnMainThread:@selector(moveToMain) withObject:nil waitUntilDone:FALSE];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 6. 定時器NSTimer用法:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_aaa158ba-412a-49e5-976d-bd61bfa902c9" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 一個可以自動關閉的Alert窗口</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
UIAlertView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">alert </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIAlertView alloc] initWithTitle:nil<br />
message:[</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">一個可以自動關閉的Alert窗口</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">delegate</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">:nil<br />
cancelButtonTitle:nil </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">NSLocalizedString(@"OK", @"OK") </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">取消任何按鈕</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> otherButtonTitles:nil];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [alert show];<br />
<br />
UIActivityIndicatorView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">indicator </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> Adjust the indicator so it is up a few pixels from the bottom of the alert </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> indicator.center </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> CGPointMake(alert.bounds.size.width</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">/</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">2</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, alert.bounds.size.height</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">40.0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
[indicator startAnimating];<br />
[alert insertSubview:indicator atIndex:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
[indicator release];<br />
<br />
[NSTimer scheduledTimerWithTimeInterval:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">3.0f</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
target:self<br />
selector:@selector(dismissAlert:)<br />
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">alert</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">testing </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">key</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> ,nil] </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">如果不用傳遞參數,那麼可以將此項設置為nil.</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> repeats:NO];<br />
<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">release alert</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
[alert release];<br />
<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) dismissAlert:(NSTimer </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)timer{<br />
<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">release timer</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
NSLog([[timer userInfo] objectForKey:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">key</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]);<br />
<br />
UIAlertView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">alert </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[timer userInfo] objectForKey:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">alert</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
[alert dismissWithClickedButtonIndex:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> animated:YES];<br />
<br />
}<br />
<br />
</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 定時器停止使用:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [timer invalidate];<br />
timer </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> nil;</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 7. 用戶缺省值NSUserDefaults讀取:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">得到用戶缺省值</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSUserDefaults </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">defs </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSUserDefaults standardUserDefaults];<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">在缺省值中找到AppleLanguages, 返回值是一個數組</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSArray</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> languages </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [defs objectForKey:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">AppleLanguages</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">all language語言 is %@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, languages);<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">在得到的數組中的第一個項就是用戶的首選語言了</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">首選語言 is %@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,[languages objectAtIndex:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">]);<br />
<br />
<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">get the language & country code</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSLocale </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">currentLocale </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSLocale currentLocale];<br />
<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Language Code is %@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, [currentLocale objectForKey:NSLocaleLanguageCode]); <br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">Country Code is %@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, [currentLocale objectForKey:NSLocaleCountryCode]); </span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 8. View之間切換的動態效果設置:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> SettingsController </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">settings </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[SettingsController alloc]initWithNibName:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">SettingsView</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> bundle:nil];<br />
settings.modalTransitionStyle </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> UIModalTransitionStyleFlipHorizontal; </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">水平翻轉</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [self presentModalViewController:settings animated:YES];<br />
[settings release];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 9.NSScrollView 滑動用法:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) scrollViewDidScroll:(UIScrollView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)scrollView{<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">正在滑動中...</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">);<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">用戶直接滑動NSScrollView,可以看到滑動條</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) scrollViewDidEndDecelerating:(UIScrollView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)scrollView {<br />
<br />
}<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> 通過其他控件觸發NSScrollView滑動,看不到滑動條</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">) scrollViewDidEndScrollingAnimation:(UIScrollView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)scrollView {<br />
<br />
}</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> </div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 10. 讀取全局的Delegate:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">KiloNetAppDelegate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">appdelegate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> (KiloNetAppDelegate </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)[[UIApplication sharedApplication] </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">delegate</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 11.鍵盤處理系列</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: green; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-size: 13px; line-height: 1.5;">set the UIKeyboard to switch to a different text field when you press return</span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">switch textField to the name of your textfield</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[textField becomeFirstResponder];</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 12. 半透明層的實現:</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_175e7821-7d92-45c9-8a67-045b665b5f77" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">+</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)showWaiting:(UIView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)parent {<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">int</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> width </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">32</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, height </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">32</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
<br />
CGRect frame </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [parent frame]; </span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[[UIScreen mainScreen] applicationFrame];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">int</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> x </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> frame.size.width;<br />
</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">int</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> y </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> frame.size.height;<br />
<br />
frame </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> CGRectMake((x </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> width) </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">/</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">2</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, (y </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> height) </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">/</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">2</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">, width, height);<br />
UIActivityIndicatorView</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> progressInd </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIActivityIndicatorView alloc] initWithFrame:frame];<br />
[progressInd startAnimating];<br />
progressInd.activityIndicatorViewStyle </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> UIActivityIndicatorViewStyleWhiteLarge;<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> frame = CGRectMake((x - 140)/2, (y - height) / 2 + height, 140, 30);</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> waitingLable.text = @"Proccesing...";</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> waitingLable.textColor = [UIColor whiteColor];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> waitingLable.font = [UIFont systemFontOfSize:15];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> waitingLable.backgroundColor = [UIColor clearColor];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> <br />
frame </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [parent frame];<br />
UIView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">theView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[UIView alloc] initWithFrame:frame];<br />
theView.backgroundColor </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [UIColor blackColor];<br />
theView.alpha </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">0.8</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
<br />
[theView addSubview:progressInd];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [theView addSubview:waitingLable];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> <br />
[progressInd release];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [waitingLable release];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> <br />
[theView setTag:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">9999</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
[parent addSubview:theView];<br />
[theView release];<br />
}<br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">+</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">(</span><span style="color: blue; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">void</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)hideWaiting:(UIView </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">)parent {<br />
[[parent viewWithTag:</span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">9999</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">] removeFromSuperview];<br />
}</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 13. 設置View的圓角:</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: green; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-size: 13px; line-height: 1.5;"> 首先應用 #import <QuartzCore/QuartzCore.h></span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">view.layer.cornerRadius </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">10</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">;<br />
view.layer.masksToBounds </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> YES;</span></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"><br />
</div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> 14. UIWebView顯示本地圖片(目前有點問題,無法正確顯示圖片):</div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div class="cnblogs_code_hide" id="cnblogs_code_open_3dc4278c-54db-4025-8c50-36f17d53eb7d" style="display: block;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSString </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">imagePath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [[NSBundle mainBundle] resourcePath];<br />
imagePath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [imagePath stringByReplacingOccurrencesOfString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">/</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> withString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
imagePath </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [imagePath stringByReplacingOccurrencesOfString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> withString:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">%20</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">];<br />
<br />
NSLog(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">fileurl=%@</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,[NSString stringWithFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">file:/%@//</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,imagePath]);<br />
<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">[self loadData:[html dataUsingEncoding:NSUTF8StringEncoding] MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"file:/%@</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">",imagePath]] ];</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><br />
</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [self loadHTMLString:html baseURL:[NSURL fileURLWithPath:[NSString stringWithFormat:</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">@"</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">file:/%@//</span><span style="color: maroon; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">"</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">,imagePath] ]];</span></div></div></div><div style="font-size: 13px; line-height: 1.4; margin-bottom: 5px; margin-left: auto; margin-right: auto; margin-top: 5px; text-indent: 0px;"> <span style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="color: black; font-size: 13px; line-height: 1.5;"> NSString </span><span style="color: black; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-size: 13px; line-height: 1.5;">path </span><span style="color: black; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-size: 13px; line-height: 1.5;"> [[NSBundle mainBundle] bundlePath];</span></span></div><div class="cnblogs_code" style="background-color: whitesmoke; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; font-family: 'Courier New'; font-size: 13px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; word-break: break-all;"><div><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> NSURL </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">*</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">baseURL </span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"> [NSURL fileURLWithPath:path];<br />
[UIWebView loadHTMLString:html baseURL:baseURL];<br />
</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">//</span><span style="color: green; font-family: 'Courier New'; font-size: 13px; line-height: 1.5;">這段代碼可以正確顯示圖片。</span></div></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1399164727595192864-7273218168309407671?l=iphonemurmur.blogspot.com' alt='' /></div>Hansonhttp://www.blogger.com/profile/03705090223241459781noreply@blogger.com0