TableView基本使用

基本步奏

  • 1设置数据源
    self.tableview.dataSource = self;
  • 2遵守协议
@interface ViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
  • 3实现方法

    有几组

    每组有几行

    每行设置什麽 内置了那些控件,自己点击command查找

/**

* 不是必须实现的方法

*

* @param tableView

*

* @return tabeleview多少分组

*/

“`objc

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 3;

}

/**
* 必须实现的方法
*
* @param tableView
* @param section
*
* @return 告诉tableview每个分组有多少行
*/
```objc
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 2;
}
else if (section == 1)
{
return 3;
}
else
{
return 4;
}
}

/**

* 对分组每行的内容进行设置

*

* @param tableView

* @param indexPath

*

* @return (UITableViewCell *)

*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[UITableViewCell alloc] init]; if (indexPath.row == 0) {
cell.textLabel.text = @"通用";
}
else if(indexPath.row == 1)
{
cell.textLabel.text = @"隐私";
}
else if (indexPath.row == 2)
{
cell.textLabel.text = @"必须";
}
else
{
cell.textLabel.text = @"得更新";
} return cell;
}

效果图:

出现的问题图:





最新文章

  1. axis2+struts拦截地址冲突问题
  2. rabbitmq性能优化之Consumer utilisation
  3. 【原创】如何在Android Studio下调试原生安卓Framework层面的源代码
  4. matlab basic operation command
  5. ios 设置声音和震动,单独控制
  6. Linux系统性能10条命令监控
  7. C语言使用宏实现2个变量的交换
  8. sql server 2008 登录 4064 错误解决办法
  9. Python即时网络爬虫项目: 内容提取器的定义(Python2.7版本)
  10. OpenCV Python教程(3、直方图的计算与显示)
  11. java验证手机号码是否合法
  12. html常用的基本标签
  13. jmeter 脚本规范
  14. BZOJ#1717:[Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+单调队列)
  15. firefox 开启安全禁用端口
  16. Collection 和 Collections;Array与Arrays的区别
  17. Leetcode:0002(两数之和)
  18. 次小生成树(POJ1679/CDOJ1959)
  19. LoadRunner监控SQLServer
  20. August 30th 2017 Week 35th Wednesday

热门文章

  1. js十进制等互相转换
  2. js中运算符的优先级
  3. ionic框架,快速开发webAPP神器。
  4. CentOS下建立本地YUM源并自动更新
  5. 第几天 switch做法 杭电
  6. C语言+ODBC+SQL 操作(向SQL里面添加数据)
  7. Jackknife,Bootstraping, bagging, boosting, AdaBoosting, Rand forest 和 gradient boosting的区别
  8. 转:yarn详解
  9. 转:Linux 内核中的 cdev_alloc和cdev_add
  10. MSSQL2005 导出excel文件