tableView的基本使用(改良版)
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
{
int i;//用来计算接受通知的次数
}
@property(nonatomic,strong)UITableView * tableView;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBarHidden = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(通知要执行的方法) name:@"有新消息了" object:nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 屏幕宽度, 屏幕高度 - 49) style:UITableViewStyleGrouped];
self.tableView.bounces = NO;
self.tableView.backgroundColor = 灰色;
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.sectionFooterHeight = 0;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];//在这里注册一下,数据源方法中就不用加判断语句了,否则数据源方法得加上if(cell == nil){创建新的cell};
}
#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
//-----为cell添加数据----
cell.xxx = @"xxxxx";.....
return cell;
}
#pragma mark UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0) {
return 300 * 屏幕宽度/375.0 + 20;
}
return 0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (条件一) {
}else{
}
}
tableView的基本使用(改良版)的更多相关文章
- office全系列激活脚本-改良版
@ECHO OFFTITLE office 全版本系统激活@echo offfor /l %%a in (8,1,16) do (for /f "tokens=*" %%i in ...
- windows全系列激活脚本-改良版.cmd
@ECHO OFFTITLE Windows 全版本系统激活cscript //nologo %Systemroot%\system32\slmgr.vbs -skms 10.1.1.12ECHO 检 ...
- office全系列激活脚本-改良版.cmd
@ECHO OFFTITLE office 全版本系统激活@echo offfor /l %%a in (8,1,16) do (for /f "tokens=*" %%i in ...
- 优化改良版:数组,List,等集合需要加逗号或其它符合转成字符串
大家经常需要数组加逗号拼接成字符串的情况传统作法就是写for,foreach拼接, 现给出优化改良版数组,List,等集合需要加逗号或其它符合转成字符串方法: List<string> l ...
- 无焦点下获取条码枪返回值的Hook(再次改良版)
针对上一个版本再次改良,上除掉无用代码,新手绝对可以看懂! using System; using System.Collections.Generic; using System.Linq; usi ...
- Python开发程序:选课系统-改良版
程序名称: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...
- php接口post提交方法 (改良版)
$postData = "reqType=2&caller=15088719619&called=15068722845"; $result = send_post ...
- Headfirst设计模式的C++实现——迭代器(Iterator)改良版
iterator.h #ifndef _ITERATOR_H_ #define _ITERATOR_H_ class Iterator { public: ; ; }; #endif menu.h # ...
- 利用反射把数据库查询到的数据转换成Model、List(改良版)
之前也写过一篇这样的博文,但是非常的粗糙. 博文地址 后来看到了一位前辈(@勤快的小熊)对我的博文的评论后,让我看到了更加优雅的实现方式,于是重构了之前的代码. public static Li ...
随机推荐
- 转:XMPP协议、MQTT协议、HTTP协议、CoAP协议的基本比较
一.先看下相关国外的专业数据对四大协议的比较: Protocol CoAP XMP ...
- 用Activator.CreateInstance代替new实现类的实例化(转)
一直想得到这样一个函数,输入一个类的名称为参数,返回一个相应的类的实例. 这在工厂模式中是非常有用的 这样,可以使程序有更高的扩展性,例如,,下面的例子 如果现在有一个类,专门用来计算交通工具的速度, ...
- centos5.6部署gcc4.7编译的程序导致问题
因为用了c++0x的一些新特性,必须使用4.6及以上的版本编译,所以使用了4.7编译,运行时提示错误 libstdc++.so.6(GLIBCXX_3.4.14) 错误 这个时候下了个glibc2.7 ...
- ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法
ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法 转载:http://blog.csdn.net/yao_qinwei/article/details/8761777 在插入模式下,按删 ...
- phpmyadmin安装教程及配置设置
phpmyadmin安装教程及配置设置 | 浏览:20304 | 更新:2013-11-07 09:50 1.一般网上下载到的phpmyadmin是一个压缩包,我们将其释放到htdocs目录中,例如h ...
- Html5+Css3 Banner Animation 多方位移动特效
背景:朋友问我小米官网的mi4的特效会做吗,可能新接的一个小网站需要用到.一直有打算研究H5C3的一些效果,趁此机会,赶紧学习一下! 效果:如图 素材 HTML: <div class=&quo ...
- ASP.NET WEB API 初探
本文初步介绍如何简单创建一个ASP.NET Web Api 程序. Web Api 顾名思义就是一个Api接口,客户端可调用此接口进行业务操作.此类应用与 ASP.NET web服务(即使用扩展名. ...
- PHP中的变量
PHP中的变量 程序是由代码与数据两部分组成,数据存储在变量,变量的本质是内存中的一个存储空间.变量对应的空间有一个名子,叫变量名,变量名用于对数据进行读写. 变量的定义 在php变量名之前必须使用' ...
- Linux 进行反编译 或者 汇编
Linux 进行反编译 或者 汇编 一.需要的工具 1.objdump 2. 3.
- What are Upgrade, Product and Package Codes used for? By pusu
Following content is reprinted from here, please go to the original website for more information. Au ...