版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、iphone开发教程中的iphone聊天应用重新配置(2)视图控制器代码清单构建6。ioschatclientviewcontroller.m启动列表7。获取ioschatclientviewcontroller.m消息列表8。ioschatclientviewcontrollerIewController.m是邮件列表10 .显示ioschatclientviewcontroller.m传输消息结尾。在牙齿部分,可以进入项目主题,实现视图控制器。代码都在一个文件中,但是将它们分成多个列表,以便在描述每个部分时更容易说明。第一部分清单6描述了应用节目的开始和视图控制器的初始化。iphone开发
2、教程构建视图控制器代码,# importioschatclientviewcontroller . h implementation ioschatclientviewcontroller synthesize message text-(idReturn self,iphone开发教程列表6。启动ioschatclientviewcontroller . m-(bool)shouldautorotatetointerfaceorientation 3360-(void)didreceivememorywarner-(void)viewDidUnload,iPhone开发教程,# import
3、 ioschatclientviewcontroller . h implementation ioschatclientviewcontrollerReturn self-(bool)shouldautorotatetointerfaceorientation :(uinterface orientation)interface orientation return yes;iphone开发教程-(void)didreceivememorywarning super didreceivememorywarning;-(void)view didunload-(void)de alloc su
4、per de alloc;这是标准iOS代码。代码包含对可变系统事件(如内存警报和存储设备分配)的回调。生产应用程序希望完全处理这些事件,但牙齿示例应用程序不希望事情变得太复杂。第一个真正的任务是提出messages.php脚本GET请求。清单7显示了此操作的代码。iPhone开发教程-(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开发教程-(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开发教
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开发教程,(void)t
7、imer callback timer release;Self getNewMessages代码开头是getNewMessages方法。牙齿方法生成请求,然后构建NSURLConnection以启动请求。还将创建存储响应数据的数据缓冲区。三个茄子事件处理函数didReceieveResponse、didReceiveData和connectionDidFinishLoading均处理数据加载的每个步骤。iPhone开发教程connectionDidFinishLoading方法如下所示,其中最后一种方法是计时器用于启动新消息请求的timerCallback:计时器超时后,将调用getNewM
8、essages方法以重新启动计时过程,最后创建新的计时器。牙齿计时器超时后,邮件检索过程将重新开始。下一节列表8处理XML解析。iphone开发教程-(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开发教程列表8。ioschatclientviewcontrolle
9、r.m解析消息,if(元素名称isequaltostring 3360 user)inuser=yes;If(元素名称isequaltostring :文本)intext=是;iphone开发教程-(void)parser :(ns XML parser *)parser found characters 3360(ns string *)string if(;string if);if(intext)msg text appendstring :字符串;iphone开发教程-(void)parser :(ns XML parser *)parser didendelement 3360(ns
10、 string *)element name namespacementMsgAdded release发行Msg使用者;Msgtext版本;iphone开发教程,element name isequaltostring : user(if)inuser=no;If(元素名称isequaltostring :文本)intext=no知道SAX语法分析的人都应该熟悉牙齿XML语法分析程序。打开或关闭标签时,如果找到文本,则提供向代码发送事件的XML。不是基于DOM的解析器,而是基于事件的解析器。事件解析器的优点是内存占用量小。但是,缺点是在解决过程中必须将所有状态存储在主机对象中,因此很难使用。
11、iphone开发教程、进程开始时所有成员变量(msgAdded、msgUser、inUser、inText等)都初始化为空字符串或false。然后,当每个标签在didStartElement方法中完成初始处理时,代码查看标签名称并设置相应的inUser或inText Boolean值。其中,foundCharacters方法处理向相应字符串中添加文本数据。didEndElement方法随后处理标签结束。也就是说,在发现结束时将已处理的消息添加到消息列表中。现在必须编写显示消息的代码。代码如清单9所示。,iphone开发教程-(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开发教程列表9。显示ioschatclientviewcontroller.m消息-(cgfloat)table view 3360(uitable view *)table view heew-(uitable view Cell),iphone开发教程,if(Cell=nil)n
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中语文+《烛之武退秦师》《鸿门宴》对比阅读课件+统编版高一语文必修下册
- 快递公司岗位责任制度
- 意识形态两个责任制度
- 房地产责任制度
- 托运人法律责任制度
- 扶贫办信访责任制度
- 技术负责责任制度
- 拆违包保责任制度
- 换届风气监督责任制度
- 推行门前五包责任制度
- 伤口负压治疗新进展
- HIV感染者心理支持方案
- 配电箱设备防护维护技术方案
- 2026年苏州工业职业技术学院单招综合素质考试题库附答案
- 2025版《煤矿安全规程》解读
- 2026年安徽水利水电职业技术学院单招职业适应性考试题库及答案1套
- 采集动脉血课件
- 2025年江西省公务员考试行测真题解析试卷(含答案)
- 剧毒从业证摸拟考试及答案解析
- 西藏高标准农田施工方案
- 隧道施工环境监测方案
评论
0/150
提交评论