#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点击按钮滚到顶部的更多相关文章

  1. JS——BOM操作(点击按钮返回顶部案例:scrollTop的用法)

    点击按钮返回顶部案例: 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  2. jQuerry点击按钮回到顶部功能

    简单实现点击按钮回到顶部功能

  3. 通过HTML+CSS+Javascript实现向下滚动滚动条出现导航栏并出现回到顶部按钮点击按钮回到顶部(一)

    回到顶部实例一 效果:默认隐藏导航栏,当滚动条滚到超过300px后导航栏和按钮出现,点击回到顶部按钮回到顶部,并隐藏导航栏和按钮(导航栏和按钮都是固定定位) <!doctype html> ...

  4. iOS 之点击按钮改变状态的图片

    .h  文件中 @property (strong, nonatomic) IBOutletUIButton *publishBtton; @property (strong, nonatomic) ...

  5. Web前端 页面功能——点击按钮返回顶部的实现方法

    1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...

  6. iOS UITableView中点击状态栏无法回滚到顶部

    // When the user taps the status bar, the scroll view beneath the touch which is closest to the stat ...

  7. 【IOS】点击按钮-去高亮-加点击效果

    (1)前提:html页面 ,手机端, (2)问题一: 在iphone上(貌似是9以后..),给div/span/...等元素上加onclick事件,根本不起作用,这是为啥捏? -- 在元素上加  cu ...

  8. 微信小程序ios点击状态栏返回顶部不好使

    最近做了一款微信小程序,各方面感觉都很完美(萝卜一直这么自信),今天设计总监告诉我你的小程序怎么返回顶部不好使呀,吓得我赶紧拿手机试试,没毛病啊,我手机(苦逼的安卓机)上点两下就回去了呀,遂去找他理论 ...

  9. iOS点击状态栏回到顶部底层实现原理

    在iOS开发中,苹果其实已经帮你实现了点击状态栏回到顶部这个功能,但我们在开发中会遇到点击不能回到顶部.其实这都和 ScrollView中的一个属性scrollsToTop有关,我们先看看苹果关于这个 ...

随机推荐

  1. Ubuntu/linux 安装 kernel-devel

    这个问题,需要安装与系统内核配套的开发包. 查看内核: uname -r 内核头文件C header files下载地址: http://rpmfind.net/linux/rpm2html/sear ...

  2. Javascript 笔记与总结(1-3)arguments

    arguments 是函数运行时的实参列表(对象),每个函数都有自己的 arguments,但不往外层函数寻找 arguments 的相关属性,即不行成链(只有 OA 形成作用域链). 例1 < ...

  3. python twisted启动定时服务

    以下是python脚本send_mms.py #############################################!/usr/bin/python# -*- coding: ut ...

  4. 如何开启mysql计划事件

    如何开启mysql计划事件 (2012-07-26 12:21:23) 转载▼ 标签: mysql 事件计划 it 分类: MySQL 首先在sql中查询计划事件的状态:SHOW VARIABLES ...

  5. 开放平台鉴权以及OAuth2.0介绍

    OAuth 2.0 协议 OAuth是一个开发标准,允许用户授权第三方网站或应用访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的内容. OAuth 2.0 ...

  6. C# Xml文件操作,解释见注释

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. pureftpd安装配置[总结]

    http://www.ttlsa.com/linux/how-to-install-pureftpd/ 看了这篇文章[几个小坑]总结如下: 1.最重要的一点,代码不要复制,有些符号肉眼看不出来. ./ ...

  8. Two's complement

    https://en.wikipedia.org/wiki/Two's_complement The two's-complement system has the advantage that th ...

  9. JsonCpp 简单使用

    [转]自: http://www.cnblogs.com/ytjjyy/archive/2012/04/17/2453348.html JsonCpp 是一个C++用来处理JSON 数据的开发包.下面 ...

  10. MVC3下的layout页面

    1.Layout页基础:如果你有使用MasterPage的经验,你将会记得如下的几个东西 A:<%@ Master %> B:<%@ Page %> C:<asp:Con ...