#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(可滚动到顶部和底部)的更多相关文章

  1. Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)

    Android ScrollView监听滑动到顶部和底部,虽然网上很多资料都有说,但是不全,而且有些细节没说清楚 使用场景: 1. 做一些复杂动画的时候,需要动态判断当前的ScrollView是否滚动 ...

  2. android去掉滑动到顶部和底部的阴影

    android去掉滑动到顶部和底部的阴影 <ListView android:id="@+id/listView" android:layout_width="ma ...

  3. [jquery]判断页面滚动到顶部和底部(适用于手机web加载)

    //判断页面滚动到顶部和底部 $(window).scroll(function(){ var doc_height = $(document).height(); var scroll_top = ...

  4. ListView去除顶部和底部边缘阴影(亲测4.4及以前的版本都适用)

    ListView滑动到顶部和底部时出现的阴影消除方法:android2.3以前用android:fadingEdge="none"android2.3以后用android:over ...

  5. ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等

    见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...

  6. jQuery&CSS 顶部和底部固定浮动工具栏 兼容IE6

    http://www.cnblogs.com/lhj588/archive/2013/04/02/2994639.html —————————————————————————————————————— ...

  7. React Native(四)——顶部以及底部导航栏实现方式

    效果图: 一步一步慢慢来: 其实刚入手做app的时候,就应该做出简单的顶部以及底部导航栏.无奈又在忙其他事情,导致这些现在才整理出来. 1.顶部导航栏:react-native-scrollable- ...

  8. App 运行后屏幕顶部和底部各留黑边问题 - iOS

    App 启动后屏幕的顶部和底部各产生一条黑边,App 的内容会被压缩在两个黑条内显示,比例失调的情况. 初步判断是启动页资源图片适配问题. 首先,查看工程 project => General ...

  9. jquery返回顶部和底部插件和解决ie6下fixed插件

    (function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...

随机推荐

  1. [转]C++ 智能指针详解

    转自:http://blog.csdn.net/xt_xiaotian/article/details/5714477 C++ 智能指针详解 一.简介 由于 C++ 语言没有自动内存回收机制,程序员每 ...

  2. docker+jenkins 部署持续集成环境

    1.使用docker container的方式安装jenkins [root@hadoop default]# docker pull jenkin 创建一个目录用于后边映射 [root@hadoop ...

  3. ACM学习历程—HDU5668 Circle(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5668 这题的话,假设每次报x个,那么可以模拟一遍, 假设第i个出局的是a[i],那么从第i-1个出局的人后,重新 ...

  4. VS2005环境下的DLL应用

    VS2005环境下的DLL应用 作者:一点一滴的Beer http://beer.cnblogs.com/ 以前写过一篇题为<VC++的DLL应用(含Demo演示)>的文章,当时是刚开始接 ...

  5. H5移动端下html上传图片被旋转问题

    iOS下,html方式使用<input type="file">上传图片,图片会被旋转.遇到这个问题js是无法解决的,html也没有相应的解决方案.只能放到后台去处理, ...

  6. 关于postman、postman interceptor的安装、配置问题

    由于app中有一些鉴权问题,需要携带浏览器的cookie. 不然的话不能够正确测试接口,就在chrome(这里下载的来源是Google商店)中添加了postman interceptor插件. 然后发 ...

  7. java文本文件读写

    java的IO系统中读写文件使用的是Reader和Writer两个抽象类,Reader中的read()和close()方法是抽象方法,Writer中的write().flush()和close()方法 ...

  8. Extjs5.0 学习之路【资源篇】

    磨刀不误砍柴工. 先收集资源,然后再开始学习之路. Extjs5.0 文件下载 API-5.0 API离线包 http://cdn.sencha.com/downloads/docs/ext-docs ...

  9. Python使用SMTP模块、email模块发送邮件

    一.smtplib模块: 主要通过SMTP类与邮件系统进行交互.使用方法如下: 1.实例化一个SMTP对象: s = smtplib.SMTP(邮件服务地址,端口号) s = smtplib.SMTP ...

  10. java 多线程系列基础篇(三)之start()和run()的区别

    概要 Thread类包含start()和run()方法,它们的区别是什么?本章将对此作出解答. start() 和 run()的区别说明 start() : 它的作用是启动一个新线程,新线程会执行相应 ...