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 ...
随机推荐
- Commons JXPath - DOM/JDOM Document Access
除了 JavaBean,JXPath 也可以访问 DOM/JDOM. 示例 XML: <?xml version="1.0" encoding="utf-8&quo ...
- django 学习-7 模型数据操作
1.首先还是创建办一个项目和一个应用 django.admin.py startproject ssj cd ssj django.admin.py startapp sdj 那 ...
- C#数组比较取值
string strs = string.Empty; string[] strArray1 = { "a", "b", "c& ...
- 并行执行的Service,以媒体转码成新格式为例
大家众所周知,IntentService内置的handler只有一个线程,而AsyncTask又只适合时间至多几秒的操作,所以我们关注使用ExecutorService建立并行执行.为了确保Servi ...
- SQL Server的三种物理连接之Hash Join(三)
简介 在 SQL Server 2012 在一些特殊的例子下会看到下面的图标: Hash Join分为两个阶段,分别为生成和探测阶段. 首先是生成阶段,将输入源中的每一个条目经过散列函数的计算都放到不 ...
- java 调用bash shell脚本阻塞的小问题的解决
java 调用bash shell脚本阻塞的小问题的解决 背景 使用java实现的web端,web端相应用户的界面操作,使用java调用bash实现的shell脚本进行实际的操作,操作完成返回执行结 ...
- Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现
为了进一步了解背景音乐和音效播放的,我们通过一个实例给大家介绍一下.如下图所示有两个场景:HelloWorld和Setting.在HelloWorld场景点击“游戏设置”菜单可以切换到Setting场 ...
- PHP标签的格式
PHP标签的格式: 1.xml格式(推荐的,标准的标记) <?php php代码?> 示例: 2.短格式 <? php代码 ?> 此种格式需要在php.ini中配置 示例 ...
- spring中jdbc的配置
本文中的JdbcTemplate的用法可以参看官方文档http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-referenc ...
- [ZZ+CH] Html5 canvas+js 时钟
总之新Blog入驻以后,又开始老习惯,到处折腾自定义的空间,放些东西. 想起以前大一的时候做过一个Javascript的时间显示器,现在想做一个时钟,当然现在老奸巨猾,会先去看一看有前辈写过没. 前辈 ...