TableView基本使用
2024-10-18 17:26:01
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;
}
效果图:
出现的问题图:
最新文章
- axis2+struts拦截地址冲突问题
- rabbitmq性能优化之Consumer utilisation
- 【原创】如何在Android Studio下调试原生安卓Framework层面的源代码
- matlab basic operation command
- ios 设置声音和震动,单独控制
- Linux系统性能10条命令监控
- C语言使用宏实现2个变量的交换
- sql server 2008 登录 4064 错误解决办法
- Python即时网络爬虫项目: 内容提取器的定义(Python2.7版本)
- OpenCV Python教程(3、直方图的计算与显示)
- java验证手机号码是否合法
- html常用的基本标签
- jmeter 脚本规范
- BZOJ#1717:[Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+单调队列)
- firefox 开启安全禁用端口
- Collection 和 Collections;Array与Arrays的区别
- Leetcode:0002(两数之和)
- 次小生成树(POJ1679/CDOJ1959)
- LoadRunner监控SQLServer
- August 30th 2017 Week 35th Wednesday
热门文章
- js十进制等互相转换
- js中运算符的优先级
- ionic框架,快速开发webAPP神器。
- CentOS下建立本地YUM源并自动更新
- 第几天 switch做法 杭电
- C语言+ODBC+SQL 操作(向SQL里面添加数据)
- Jackknife,Bootstraping, bagging, boosting, AdaBoosting, Rand forest 和 gradient boosting的区别
- 转:yarn详解
- 转:Linux 内核中的 cdev_alloc和cdev_add
- MSSQL2005 导出excel文件