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有关,我们先看看苹果关于这个 ...
随机推荐
- angJs使选中的li背景颜色不同
<!doctype html><html><head><meta charset="UTF-8"><title>test ...
- [SHELL实例] (转)最牛B的 Linux Shell 命令 (一)
本文编译自commandlinefu.com ( 应该是 Catonmat ) 的系列文章 Top Ten One-Liners from CommandLineFu Explained .作为一个由 ...
- Yii源码阅读笔记(五)
Object 是一个基础类,实现了属性的功能,其基本内容如下: namespace yii\base; use Yii; /** * Object is the base class that imp ...
- WEB系统开发
最近根据项目组需求做了web工作流程系统,就是一个简单的web管理系统,取代原先使用的excel表格,在VS2008下面开发,数据库使用Mysql,使用Mysql-connecte 5.0与数据库连接 ...
- Web Service性能测试方案
目录: 1.web Service简介 2.SoapUI介绍 3.使用SoapUI进行web service性能测试 4.使用LR进行web service性能测试 5.使用JMeter进行web s ...
- 纸牌project
用range[0,8)的列表表示牌,这些数字要出现两次.我们建议你通过连接两个range[0,8)的列表来创建这个list.利用Docs来安排列表串联操作 写一个draw handler啥样的draw ...
- Law of total probability
https://en.wikipedia.org/wiki/Law_of_total_probability the total probability of an outcome which can ...
- linux ntp时间同步
linux ntp时间同步 一.搭建时间同步服务器1.编译安装ntp serverrpm -qa | grep ntp若没有找到,则说明没有安装ntp包,从光盘上找到ntp包,使用rpm -Uvh n ...
- SQLServer2008:助您轻松编写T-SQL存储过程(原创)【转】
本文主要介绍 SQLServerExpress2008不用第三方工具调试T-SQL语句,经过本文的介绍,用SQLSERVER2008 Manage studio 编写.调试T-SQL存储过程都将是 ...
- JSON数据转换为字典型
-(NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString { NSData *JSONData = [JSONS ...