iOS学习之TableView的简单使用.pdf
《iOS学习之TableView的简单使用.pdf》由会员分享,可在线阅读,更多相关《iOS学习之TableView的简单使用.pdf(7页珍藏版)》请在三一文库上搜索。
1、分类: iOS 开发入门 iOS 学习之Table View的简单使用 2012-06-07 20:179804 人阅读评论(22)收藏举报 headerimageImageiosiOSIOStablexcode Table View简单描述: 在iPhone 和其他 iOS 的很多程序中都会看到Table View 的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View ,Table View 主要 分为以下两种: Plain :这是普通的列表风格 Grouped :这是分块风格。 对于 UITableView ,我們有一些特殊的概念和术语,比如说我们成Table
2、View 的一行为 Cell,而许多的Cell可以组成 Section ,每个 Section 上下又分別有 Header 和Footer ,许多个的Section 则组成了整个Table ,当然 Table 也有 Header 和Footer ,下面看两种图就能明白这几个拗口名词了: : 现在理论知识了解的差不多了。今天先做一个Plain 样式的例子,这样加强对Table view 的熟练使用。 1、新建项目 新建一个 Single View Application,命名为TableViewDemo,开发环境是: Xcode 4.3,iPhone 5.1 模拟器。 2 、Table View
3、放上控件 打开ViewController.xib文件,往 ViewController.xib界面上拖拽一个 Table View 控件到现有的 View 上, 对齐。 3 、连接新添加的TableView和ViewController。 选中新添的 TableView 控件,打开连接检查器(Connection Inspector), 找到delegate 和datasource并点中圆圈拉线连接到左边Files Owner图标上,为什么要 把这两个连接 Files Owner上呢?这是因为 iOS 使用的MVC 设计模式, View 和ViewController之间的对应关系,需要一个
4、桥梁来进行连接的(即,对于一个视图, 他如何知道自己的界面的操作应该由谁来响应),这个桥梁就是Files Owner。 4、打开 ViewController.h,添加协议和Property (类似与 java 里的实现接口) cpp 01.# i mpor t 02. 03. i n t er f ace Vi ewCon t r ol l er:UI Vi e wCont r ol l e r 04. pr oper t y ( st r on g,nonat omi c )NSAr r ay* l i st ; 05. en d 5、打开 .m文件, 添加: cpp 01. sy nt
5、hesi ze l i st= _l i st ; 这是发现有两个警告,提示未完成的实现,这提示的是UITableViewDelegate, UITableViewDataSource这个两个头文件里的协议的方法未实现。待会我们去实现它。 6、建立数据 cpp 01.-( voi d) vi e wDi dL oa d 02. 03. supervi ewDi d Load ; 04./ /Do a nyad di t i onals et up af t e rl oadi n g t he vi ew,t yp i c al l yf r o m a n i b . 05.NSAr r a
6、y* ar r ay= NSAr r ayal l o ci ni t Wi t hObj ect s: “ 美国 “ , “ 菲律宾 “ , 06. “ 黄岩岛 “ , “ 中国 “ , “ 泰国 “ , “ 越南 “ , “ 老挝 “ , 07. “ 日本 “,ni l ; 08.sel f . l i st=ar r ay; 09. 10. 11.-( voi d) vi e wDi dUnl oad 12. 13. supervi ewDi d Unl oad ; 14./ /Rel e as e a nyr et ai ne d su bvi ews oft he mai n vi
7、ew. 15.sel f . l i st=ni l ; 16. 17. 7、生成 row 关键的步骤来了,实现tableview 添加数据源,返回 TableView 的行数,返回各行 cell实例。 cpp 01.-( UI Tabl eVi e wCe l l* ) t abl e Vi ew: ( UI Tabl eVi ew * ) t abl eVi ew 02.ce l l For Ro wAt I ndex Pa t h : ( NSI ndexPat h * ) i ndexPat h 03. 04.st at i cNSSt r i n g * Tabl e Sa m p
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- iOS 学习 TableView 简单 使用
链接地址:https://www.31doc.com/p-5012161.html