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有关,我们先看看苹果关于这个 ...
随机推荐
- Nginx 笔记与总结(12)Nginx URL Rewrite 实例(ecshop)
访问项目地址:http://192.168.254.100/ecshop 某个商品的 URL:http://192.168.254.100/ecshop/goods.php?id=3 现在需要实现把以 ...
- python 线程使用
################# 线程演示脚本 ####################### #coding=utf-8import threadingfrom time import ctim ...
- 23个MySQL常用查询语句
23个MySQL常用查询语句 一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!> ...
- 搭建C语言开发环境
大学的时候有数据结构这门课,但...终究还是得学.电脑是win8的,根据网上的教程倒是能安装成功vc6.0并且能够打开新建工程,但是一编译运行就提示兼容性问题. 首先安装C语言编译器.下载MinGw ...
- ROSE User Case View
用例视图(User Case View) 在面向对象的分析过程中,此视图应该是需求分析的过程中采用,主要包括如下过程 01涉众分析--->02业务分析--->03概念分析--->04 ...
- ubuntu下交叉编译windows c程序
简介 采用mingw32可以在linux下直接编译c程序输出为windows下的exe程序或dll链接库. 个人编译的纯c程序(不含winapi),主要是c99程序,通常采用gcc/cc编译调试后,再 ...
- jdk 8 lambda表达式 及在Android Studio的使用示例
以前觉得java让人觉得有趣的一个特点是支持:匿名内部类,而最近发现jdk8已支持lambda并有更简便的方式,来实现匿名内部类. 这会让程序员更舒服,更喜欢java. 多年前觉得java语法和C#语 ...
- onmouseenter与onmouseover
简单的说: mouseenter第一次进入这个元素的某个子元素时触发.一旦触发后,在mouseleave之前,鼠标在这个元素的子元素上触发mouseenter事件,不会触发这个元素的mouseente ...
- 免费真机调试 -- Xcode7以上版本
刚新安装了Xcode7 , 据说这个版本可以免费真机调试,于是用了一个新的AppID测试了,发现真的可以免费真机调试了呢!新的appId账号(随便一个苹果手机账号就行),没有支付每年的99美刀,也没有 ...
- Java学习-028-JSON 之二 -- 数据读取
JSON数据由 JSONObject.JSONArray.key_value 组合而成.通常来说,JSONObject 可以包含 JSONObject.JSONArray.key_value:JSON ...