#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. axure下载及汉化

    第一步:下载axure rp 6.5英文原版 axure6.5官方英文下载地址: Windows版:http://t.cn/zW7JifS 第二步:安装汉化语言包 axure6.5汉化语言包中文包下载 ...

  2. BW里转换简单常用ABAP

    用户查看的是当时的物料折让,那你必然要给物料加个时间,才好区分.总是以现在最新的物料状态查看历史数据会出现问题.当时这个物料是折让的,现在不折让了.数据会有问题.加个DSO.做一个时间记录.读取系统时 ...

  3. ionic2——apk签名

    1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序,我们需要对我们发布的APK文件进行唯一签名,保证我们每次发布的版本 ...

  4. idea下建立bootstrap项目

    环境准备: 1.创建一个static web名为bootstrapDemo 2.在bootstrapDemo文件夹下安装bower npm install bower 会自动产生node-module ...

  5. Sunday算法

        Sunday算法是Daniel M.Sunday于1990年提出的字符串模式匹配.其核心思想是:在匹配过程中,模式串发现不匹配时,算法能跳过尽可能多的字符以进行下一步的匹配,从而提高了匹配效率 ...

  6. git教程4-创建分支与删除分支

    一.分支的理解 分支,即branch,用于从主分支(master)中新开辟出一个分支,用于对文件进行修改.这部分修改的内容在新的分支未融合到主分支的情况下,主分支是看不见的.新的分支相当于开辟了新的修 ...

  7. php 与 Smarty 中的 isset

    今天在做一个分页模块的时候,在获取前端返回的当前页时,烦了一个大错!本来应该是这样子滴: 而咱却写成了这个样子: 在php里输出测试都没错,结果到Smarty里就被拒了! 测试结果是 这货跟谁都相等, ...

  8. CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)

    Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such ...

  9. Docker 容器相关技术

    Docker 依赖的Linux内核特性 Namespaces 命名空间 Control groups (cgroups) 控制组 理解这两个特性,能够更好的帮助我们理解docker的资源分配和管理 N ...

  10. MSSQL日誌傳輸熱備份注意事項

    主次數據庫需要新增一個用戶,並設定agent服務用此用戶執行 主次數據庫需要設定共享目錄並擁有讀/寫權限,用anent執行用戶即可 如果新增日誌傳輸時順便初始化數據庫記得次數據庫主機目錄給寫權限,否則 ...