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 ...
随机推荐
- Linux内核主要由哪几部分组成?每部分的作用?
. Linux内核主要由哪几部分组成?每部分的作用? 参考答案: Linux内核主要由五个子系统组成:进程调度,内存管理,虚拟文件系统,网络接口,进程间通信. 进程调度(SCHED):控制进程对C ...
- AOP注解式拦截
1. 自己定义的拦截注解 package com.spring.aop; import java.lang.annotation.Documented; import java.lang.annota ...
- hive 遇到的问题及解决方法
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.StandbyException): Operation category RE ...
- L122
These plants have much of the same nutritional value that a real plant has. Search giant Google says ...
- dyci——IOS动态代码注入
有时候用xib,更改了布局需要重新运行才可以看到效果,对于比较复杂的应用尤其浪费时间,下面介绍一个工具dyci-不需要重Run应用,也能看到效果 yci的网址:https://github.com/D ...
- 开发mis系统用到的技术
1. b/s架构:就broser/server,浏览器/服务器的说法.服务器端要运行tomcat,提供链接数据库服务供java代码读写数据,这个可以在eclipse中配置运行.浏览器则解释jsp或ht ...
- 洛谷 P2822 组合数问题
题目描述 组合数C_n^mCnm表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的 ...
- asp.net 打印控件使用方法
打印的效果及控制性虽然不是很好,但是也能勉强使用,应付一般的打印还是 可以的了.代码如下所示: 代码 复制代码 代码如下: //调用PrintControl.ExecWB(?,?)实现直接打印和打印预 ...
- windows10环境下运行Debug
1. 什么是Debug? Debug是DOS.Windows都提供的实模式(8086方式)程序的调试工具. 使用它,可以查看CPU各种寄存器中的内容.内存的情况和在机器码级别跟踪程序的运行. 2. 常 ...
- Windows10:怎么安装whl文件
whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件.使得可以在不具备编译环境的情况下,选择合适自己的python环境进行安装.安装方法很简单,进入命令行输入pip instal ...