TableView基本使用
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;
}
效果图:
出现的问题图:
TableView基本使用的更多相关文章
- iOS有关横向TableView的东西
之前看到Apple store里面有横向的tableview,当然也有可能是collectionview啦. 尤其是项目中只有一条那么需要横向滑动的东西,就没有必要使用庞大的collectionvie ...
- tableView显示第一个cell有偏移问题
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0 ...
- [tableView reloadData] 和 runloop
需要[tableView reloadData]后需要立即获取tableview的cell.高度,或者需要滚动tableview,那么,直接在reloadData后执行代码是会有问题的. 断点调试感觉 ...
- 【代码笔记】iOS-一个tableView,两个section
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【Swift】Alamofile网络请求数据更新TableView的坑
写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...
- TableView 滑动收起键盘
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; 拖拽tableView就会收起键盘
- 关于TableView上有一段留白的解决方法
当cell的类型是plaint类型时 直接设置self.automaticallyAdjustsScrollViewInsets=NO; 还有要注意检查你自己设置的frame是否正确 当cel ...
- iOS监听tableView组头切换事件
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSIntege ...
- 【原】iOS学习之tableView的常见BUG
1.TableView头视图不随视图移动,头视图出现错位 错误原因:tableView的 UITableViewStyle 没有明确的声明 解决方法:在tableView声明的时候明确为 UITabl ...
- 两种让tableview返回顶部的方法
1. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animat ...
随机推荐
- JNDI Tutorial
Naming Concepts A fundamental facility in any computing system is the naming service--the means by w ...
- Mysql 5.6 Cmake 编译安装
MySQL编译安装 环境: OS: CentOS 6.6x64 mini mysql: mysql-5.6.251. mysql 下载: http://dev.mysql.com/downloads/ ...
- 兄弟连面试宝典php
学历这个事情是企业招聘经常设置的一道门槛,我们不能说学历高就能力高,也不能说学历低能力就差,那如何辩证回答这个问题呢?回答提示:学历不一定完全代表能力,虽然我的学历不够硬但是我会在技术上更努力更认真, ...
- JAVA - 多线程的同步
多线程的同步 1. 锁对象. 应用场景:当某个数据可能被其他线程修改时,给涉及到数据的方法上锁,保证同一时刻只有拥有这个锁的线程能访问该数据,其他要调用这个方法的线程被阻塞.注意:必须是不同线程访问同 ...
- 关于iOS上的对象映射公用方法-备
具体的使用方法,请见下面说明,或者见工程里的单元测试代码.或者,参考原始文档: https://github.com/mystcolor/JTObjectMapping 使用方法 ======== 绝 ...
- Host myCloudData.net on your own server (支持自建服务器)
http://www.myclouddata.net/#/home Host myCloudData.net on your own serverUse the myCloudData.net SDK ...
- curl 提交请求
http://forums.phpfreaks.com/topic/194255-curl-sending-array-as-post-value/ http://www.cnblogs.com/ch ...
- mysql undo
mysql> show variables like '%undo%'; +-------------------------+-------+ | Variable_name | Value ...
- Subarray Sum Closest
Question Given an integer array, find a subarray with sum closest to zero. Return the indexes of the ...
- hadoop2.2.0 MapReduce分区
package com.my.hadoop.mapreduce.partition; import java.util.HashMap;import java.util.Map; import org ...