UITableView(可滚动到顶部和底部)
#import "RootViewController.h"
#define width [UIScreen mainScreen].bounds.size.width
#define height [UIScreen mainScreen].bounds.size.height
#define topH 64
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *rowData; @end @implementation RootViewController - (void)loadView
{
[super loadView];
// 初始化view
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(, , width, topH)];
aView.backgroundColor = [UIColor grayColor];
[self.view addSubview:aView];
// 初始化leftButton
SEL leftSel = NSSelectorFromString(@"scrollToTop:");
UIButton *leftBtn = [self setupButtonWithTitle:@"top" withFrame:CGRectMake(, , , topH - ) withSelector:leftSel];
[self.view addSubview:leftBtn];
// 初始化rigthButton
SEL rightSel = NSSelectorFromString(@"scrollToBottom:");
UIButton *rightBtn = [self setupButtonWithTitle:@"bottom" withFrame:CGRectMake(width - - , , , topH-) withSelector:rightSel];
[self.view addSubview:rightBtn];
// 初始化_tableView
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(, topH,width, height - topH) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView]; }
/**
* 初始化Button
*
* @param aTitle Button的标题
* @param aFrame Button的框架
* @param aSelector Button的方法
*
* @return Button
*/
- (UIButton *)setupButtonWithTitle:(NSString *)aTitle withFrame:(CGRect)aFrame withSelector:(SEL)aSelector
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = aFrame;
[btn setTitle:aTitle forState:];
btn.titleLabel.font = [UIFont systemFontOfSize:];
[btn addTarget:self action:aSelector forControlEvents:UIControlEventTouchUpInside];
return btn;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
}
/**
* 加载数据
*/
-(void)loadData
{
if (self.rowData!=nil)
{
[self.rowData removeAllObjects];
self.rowData=nil; }
self.rowData = [[NSMutableArray alloc] init];
for (int i= ; i<;i++)
{
[self.rowData addObject:[NSString stringWithFormat:@"Row: %i",i]];
}
[self.tableView reloadData];
} - (void)scrollToTop:(UIButton *)sender
{
NSIndexPath *topRow = [NSIndexPath indexPathForRow: inSection:];
[self.tableView scrollToRowAtIndexPath:topRow atScrollPosition:UITableViewScrollPositionTop animated:YES];
} - (void)scrollToBottom:(UIButton *)sender
{
NSIndexPath *bottomRow = [NSIndexPath indexPathForRow:[self.rowData count]- inSection:];
[self.tableView scrollToRowAtIndexPath:bottomRow atScrollPosition:UITableViewScrollPositionBottom animated:YES];
} #pragma mark -UITableView delegates-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.rowData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [self.rowData objectAtIndex:indexPath.row];
return cell;
} @end
UITableView(可滚动到顶部和底部)的更多相关文章
- Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)
Android ScrollView监听滑动到顶部和底部,虽然网上很多资料都有说,但是不全,而且有些细节没说清楚 使用场景: 1. 做一些复杂动画的时候,需要动态判断当前的ScrollView是否滚动 ...
- android去掉滑动到顶部和底部的阴影
android去掉滑动到顶部和底部的阴影 <ListView android:id="@+id/listView" android:layout_width="ma ...
- [jquery]判断页面滚动到顶部和底部(适用于手机web加载)
//判断页面滚动到顶部和底部 $(window).scroll(function(){ var doc_height = $(document).height(); var scroll_top = ...
- ListView去除顶部和底部边缘阴影(亲测4.4及以前的版本都适用)
ListView滑动到顶部和底部时出现的阴影消除方法:android2.3以前用android:fadingEdge="none"android2.3以后用android:over ...
- ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等
见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...
- jQuery&CSS 顶部和底部固定浮动工具栏 兼容IE6
http://www.cnblogs.com/lhj588/archive/2013/04/02/2994639.html —————————————————————————————————————— ...
- React Native(四)——顶部以及底部导航栏实现方式
效果图: 一步一步慢慢来: 其实刚入手做app的时候,就应该做出简单的顶部以及底部导航栏.无奈又在忙其他事情,导致这些现在才整理出来. 1.顶部导航栏:react-native-scrollable- ...
- App 运行后屏幕顶部和底部各留黑边问题 - iOS
App 启动后屏幕的顶部和底部各产生一条黑边,App 的内容会被压缩在两个黑条内显示,比例失调的情况. 初步判断是启动页资源图片适配问题. 首先,查看工程 project => General ...
- jquery返回顶部和底部插件和解决ie6下fixed插件
(function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...
随机推荐
- LeetCode OJ:Binary Tree Level Order Traversal II(二叉树的层序遍历)
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- @angular/cli项目构建--modal
环境准备: cnpm install ngx-bootstrap-modal --save-dev impoerts: [BootstrapModalModule.forRoot({container ...
- Nhibernate系列学习之(二) 简单增删改查
实例中解决方案简单的创建三层架构,符合开发过程中最简单的运用: 1:首先在数据库中创建一个表T_School,脚本如下: USE [TestDb] GO /****** 对象: Table [dbo] ...
- 获取url参数并且中文不乱码的方法
function getUrlArgument(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- bzoj 4503 两个串——FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4503 翻转T,就变成卷积.要想想怎么判断. 因为卷积是乘积求和,又想到相等的话相减为0,所以 ...
- bzoj 1898 [Zjoi2005]Swamp 沼泽鳄鱼——矩阵快速幂
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1898 当然是邻接矩阵做转移矩阵来快速幂. 对于鳄鱼,好在它们周期的lcm是12,也就是每12 ...
- xftp连接不上阿里云服务器
打开xftp默认是使用FTP协议,要连接到云服务器,需要将协议改为SFTP 连接成功
- Linux基础命令-系统时间
Linux启动时从硬件读取日期和时间信息,读取完成以后,就不再与硬件相关联 Linux的两种时钟 系统时钟:由Linux内核通过CPU的工作频率进行的: date:显示系统时间 +%D +%F dat ...
- CentOS6.5下安装mongodb
MongoDB是目前最常用的NoSQL-非关系型数据库. 本文将介绍在CentOS下如何通过yum安装MongoDB. 1.首先在CentOS6.5下,编辑Mongo的yum源: 在/etc/yum. ...
- HDU5475(线段树)
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...