iPhone開發(fā)教程之重新構建 iPhone 聊天應用程序(二).ppt_第1頁
iPhone開發(fā)教程之重新構建 iPhone 聊天應用程序(二).ppt_第2頁
iPhone開發(fā)教程之重新構建 iPhone 聊天應用程序(二).ppt_第3頁
iPhone開發(fā)教程之重新構建 iPhone 聊天應用程序(二).ppt_第4頁
iPhone開發(fā)教程之重新構建 iPhone 聊天應用程序(二).ppt_第5頁
已閱讀5頁,還剩31頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、iphone開發(fā)教程中的iphone聊天應用重新配置(2)視圖控制器代碼清單構建6。ioschatclientviewcontroller.m啟動列表7。獲取ioschatclientviewcontroller.m消息列表8。ioschatclientviewcontrollerIewController.m是郵件列表10 .顯示ioschatclientviewcontroller.m傳輸消息結尾。在牙齒部分,可以進入項目主題,實現(xiàn)視圖控制器。代碼都在一個文件中,但是將它們分成多個列表,以便在描述每個部分時更容易說明。第一部分清單6描述了應用節(jié)目的開始和視圖控制器的初始化。iphone開發(fā)

2、教程構建視圖控制器代碼,# importioschatclientviewcontroller . h implementation ioschatclientviewcontroller synthesize message text-(idReturn self,iphone開發(fā)教程列表6。啟動ioschatclientviewcontroller . m-(bool)shouldautorotatetointerfaceorientation 3360-(void)didreceivememorywarner-(void)viewDidUnload,iPhone開發(fā)教程,# import

3、 ioschatclientviewcontroller . h implementation ioschatclientviewcontrollerReturn self-(bool)shouldautorotatetointerfaceorientation :(uinterface orientation)interface orientation return yes;iphone開發(fā)教程-(void)didreceivememorywarning super didreceivememorywarning;-(void)view didunload-(void)de alloc su

4、per de alloc;這是標準iOS代碼。代碼包含對可變系統(tǒng)事件(如內(nèi)存警報和存儲設備分配)的回調(diào)。生產(chǎn)應用程序希望完全處理這些事件,但牙齒示例應用程序不希望事情變得太復雜。第一個真正的任務是提出messages.php腳本GET請求。清單7顯示了此操作的代碼。iPhone開發(fā)教程-(void)get new messages nsstring * URL=nsstring stringwithformat 3360 3358 localhost/chat/mest Past=ioschatclientviewcontroller.m消息,nsurl connection * conn=n

5、surl connection allocing If(conn)received data=nsmutataElse,chate開發(fā)教程-(void)connection 3360(nsurl connection *)connection didreceiveresponse 3360(nsurl RESS-()chat parser=nsxml parser alloc initwith data 3360 received data;chat parser setdelegate : self;ChatParser parseReceivedData release,iphone開發(fā)教

6、程,messageList reloadDatans Invocation * Invocation=ns Invocation invocationwithmethodsignature : self methodsignatureforselector 3360 selector(iinInvocation set selector :選擇器(timer callback);timer=ns timer scheduledtimerwithtimeinterval :5.0 invocation : invocation repeats 3360 no;iphone開發(fā)教程,(void)t

7、imer callback timer release;Self getNewMessages代碼開頭是getNewMessages方法。牙齒方法生成請求,然后構建NSURLConnection以啟動請求。還將創(chuàng)建存儲響應數(shù)據(jù)的數(shù)據(jù)緩沖區(qū)。三個茄子事件處理函數(shù)didReceieveResponse、didReceiveData和connectionDidFinishLoading均處理數(shù)據(jù)加載的每個步驟。iPhone開發(fā)教程connectionDidFinishLoading方法如下所示,其中最后一種方法是計時器用于啟動新消息請求的timerCallback:計時器超時后,將調(diào)用getNewM

8、essages方法以重新啟動計時過程,最后創(chuàng)建新的計時器。牙齒計時器超時后,郵件檢索過程將重新開始。下一節(jié)列表8處理XML解析。iphone開發(fā)教程-(void)parser :(ns XML parser *)parser did startelement 3360(ns string *)element name namesparems guser=nsmutablestring alloc init;msg text=nsmutable string alloc init;InUser=否;InText=否;iphone開發(fā)教程列表8。ioschatclientviewcontrolle

9、r.m解析消息,if(元素名稱isequaltostring 3360 user)inuser=yes;If(元素名稱isequaltostring :文本)intext=是;iphone開發(fā)教程-(void)parser :(ns XML parser *)parser found characters 3360(ns string *)string if(;string if);if(intext)msg text appendstring :字符串;iphone開發(fā)教程-(void)parser :(ns XML parser *)parser didendelement 3360(ns

10、 string *)element name namespacementMsgAdded release發(fā)行Msg使用者;Msgtext版本;iphone開發(fā)教程,element name isequaltostring : user(if)inuser=no;If(元素名稱isequaltostring :文本)intext=no知道SAX語法分析的人都應該熟悉牙齒XML語法分析程序。打開或關閉標簽時,如果找到文本,則提供向代碼發(fā)送事件的XML。不是基于DOM的解析器,而是基于事件的解析器。事件解析器的優(yōu)點是內(nèi)存占用量小。但是,缺點是在解決過程中必須將所有狀態(tài)存儲在主機對象中,因此很難使用。

11、iphone開發(fā)教程、進程開始時所有成員變量(msgAdded、msgUser、inUser、inText等)都初始化為空字符串或false。然后,當每個標簽在didStartElement方法中完成初始處理時,代碼查看標簽名稱并設置相應的inUser或inText Boolean值。其中,foundCharacters方法處理向相應字符串中添加文本數(shù)據(jù)。didEndElement方法隨后處理標簽結束。也就是說,在發(fā)現(xiàn)結束時將已處理的消息添加到消息列表中。現(xiàn)在必須編寫顯示消息的代碼。代碼如清單9所示。,iphone開發(fā)教程-(ns integer)numberofsectionsintable

12、view 3360(uitable view *)table view return 1;-(ns integer)table view :(uitable view *)我的table view number ofrows insection 3360(ns integer)section reture 0,iphone開發(fā)教程列表9。顯示ioschatclientviewcontroller.m消息-(cgfloat)table view 3360(uitable view *)table view heew-(uitable view Cell),iphone開發(fā)教程,if(Cell=nil)n

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論