iOS UITableView点击按钮滚到顶部
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = [[RootViewController alloc] init]; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
#import "RootViewController.h" @interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableView;
NSMutableArray *datas;
} @end @implementation RootViewController - (void)loadView{
[super loadView];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - ) style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView]; [self initializeButtonWithFrame:CGRectMake(, ,, ) title:@"滚到顶部" action:@selector(scrollToTop:)];
[self initializeButtonWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - , , , ) title:@"滚到底部" action:@selector(scrollToButtom:)];
} - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"测试"; datas = [[NSMutableArray alloc] init];
for (int i = ; i < ; i++) {
NSString *str = [NSString stringWithFormat:@"row:%d",i];
[datas addObject:str];
} }
/**
* 初始化按钮
*
* @param frame 尺寸
* @param title 标题
* @param aSEL 按钮的方法
*/
- (void)initializeButtonWithFrame:(CGRect)frame title:(NSString*)title action:(SEL)aSEL{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor grayColor];
btn.frame = frame;
[btn setTitle:title forState:];
[btn addTarget:self action:aSEL forControlEvents:UIControlEventTouchUpInside];
btn.backgroundColor = [UIColor grayColor];
[self.view addSubview:btn];
} - (void)scrollToTop:(UIButton*)sender{
NSLog(@"滚到顶部");
NSIndexPath *topRow = [NSIndexPath indexPathForRow: inSection:];
[_tableView scrollToRowAtIndexPath:topRow atScrollPosition:UITableViewScrollPositionTop animated:YES];
} - (void)scrollToButtom:(UIButton*)sender{
NSLog(@"滚到底部");
NSIndexPath *buttomRow = [NSIndexPath indexPathForRow:datas.count - inSection:];
[_tableView scrollToRowAtIndexPath:buttomRow atScrollPosition:UITableViewScrollPositionBottom animated:YES];
} #pragma mark -- tableView的代理 --
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return datas.count;
} - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = datas[indexPath.row];
return cell;
} @end
iOS UITableView点击按钮滚到顶部的更多相关文章
- JS——BOM操作(点击按钮返回顶部案例:scrollTop的用法)
点击按钮返回顶部案例: 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- jQuerry点击按钮回到顶部功能
简单实现点击按钮回到顶部功能
- 通过HTML+CSS+Javascript实现向下滚动滚动条出现导航栏并出现回到顶部按钮点击按钮回到顶部(一)
回到顶部实例一 效果:默认隐藏导航栏,当滚动条滚到超过300px后导航栏和按钮出现,点击回到顶部按钮回到顶部,并隐藏导航栏和按钮(导航栏和按钮都是固定定位) <!doctype html> ...
- iOS 之点击按钮改变状态的图片
.h 文件中 @property (strong, nonatomic) IBOutletUIButton *publishBtton; @property (strong, nonatomic) ...
- Web前端 页面功能——点击按钮返回顶部的实现方法
1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...
- iOS UITableView中点击状态栏无法回滚到顶部
// When the user taps the status bar, the scroll view beneath the touch which is closest to the stat ...
- 【IOS】点击按钮-去高亮-加点击效果
(1)前提:html页面 ,手机端, (2)问题一: 在iphone上(貌似是9以后..),给div/span/...等元素上加onclick事件,根本不起作用,这是为啥捏? -- 在元素上加 cu ...
- 微信小程序ios点击状态栏返回顶部不好使
最近做了一款微信小程序,各方面感觉都很完美(萝卜一直这么自信),今天设计总监告诉我你的小程序怎么返回顶部不好使呀,吓得我赶紧拿手机试试,没毛病啊,我手机(苦逼的安卓机)上点两下就回去了呀,遂去找他理论 ...
- iOS点击状态栏回到顶部底层实现原理
在iOS开发中,苹果其实已经帮你实现了点击状态栏回到顶部这个功能,但我们在开发中会遇到点击不能回到顶部.其实这都和 ScrollView中的一个属性scrollsToTop有关,我们先看看苹果关于这个 ...
随机推荐
- ProtocalBuffers学习记录
Google Protocol Buffer 的使用和原理 Google Protocol Buffers 概述 Google Protocol Buffers 入门 Protocol Buffers ...
- Direct基础学习系列3 绘制+实例
3.1.1顶点缓存 索引缓存 放置在显存中能够加快绘制速度 创建顶点缓存 HRESULT CreateVertexBuffer( UINT Length, //为缓存分配的字节数 DWORD Usag ...
- ATT 汇编语法
在研华的pc104上使用看门狗要使用汇编.使用汇编来修改CMOS里面的参数.也就是内联汇编.linux下gcc只支持ATT汇编.所以这儿有必要将ATT语法学习学习.以后需要的时候翻出来温习温习. ...
- svn update 失败 且 clean up失败解决方法
当出现这种情况时,大多数是因为svn的数据库还有队列没处理完.而我们要做到仅仅是把队列清除即刻. 具体做法是: 1.下载sqlite3.exe下载地址:sqlite官网http://www.sqlit ...
- Day09
Servlet概述 生命周期方法: void init(ServletConfig):出生之后(1次): void service(ServletRequest request, ServletRes ...
- Python之 continue继续循环和多重循环
Python之 continue继续循环 在循环过程中,可以用break退出当前循环,还可以用continue跳过后续循环代码,继续下一次循环. 假设我们已经写好了利用for循环计算平均分的代码: L ...
- VS小技巧
1."清理解决方案":在对程序进行分发.上传时时常需要压缩解决方案文件夹,这时如果还嫌文件太大,可以在VS里右键解决方案---清理解决方.完成后,则该解决方案下的所有项目的将所有中 ...
- HBase HDFS目录树
一.0.94-cdh4.2.1版本系统级别的一级目录如下,用户自定义的均在这个/hbase 下的一级子目录下/hbase/-ROOT-/hbase/.META./hbase/.archive/hbas ...
- Android源码剖析之Framework层实战版(Ams管理Activity启动)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 讲到实战,就不得不拿两个例子来说明,本篇想拿的是应用最广泛的两个:Ams和Wms,一个管理activ ...
- Android 代码中文字在手机上显示乱码问题解决方法
在学习Android过程中,用于测试时发现,代码中的中文在真机上会显示乱码, 网上查阅了些资料,参考如下: http://www.androidchina.net/3024.html http://b ...