如何获取UITableView中cell的frame值

如何获取UITableView中cell的frame值

这个可以用来处理UITableView弹出键盘的问题

本人视频教程系类   iOS中CALayer的使用

效果:

源码:

//
//  ViewController.m
//  TableViewCellFrame
//
//  Created by YouXianMing on 14/12/24.
//  Copyright (c) 2014年 YouXianMing. All rights reserved.
//

#import "ViewController.h"

static NSString *YOU_XIAN_MING = @"REUSED_FLAG";

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView  *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 关闭状态栏
    [UIApplication sharedApplication].statusBarHidden = YES;

    // 创建tableView
    [self createTableView];
}

#pragma mark - TableView相关
- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                  style:UITableViewStylePlain];
    self.tableView.delegate   = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:YOU_XIAN_MING];
    [self.view addSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell    = [tableView dequeueReusableCellWithIdentifier:YOU_XIAN_MING];
    cell.textLabel.text      = [NSString stringWithFormat:@"YouXianMing - %02ld", (long)indexPath.row];
    cell.textLabel.textColor = [UIColor grayColor];

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // 获取对应cell的rect值(其值针对于UITableView而言)
    CGRect rect = [self.tableView rectForRowAtIndexPath:indexPath];

    // 做动画效果
    NSLog(@"%@", NSStringFromCGRect(rect));
    [self.tableView setContentOffset:CGPointMake(rect.origin.x, rect.origin.y)
                            animated:YES];
}

@end

关键的地方:

时间: 2024-08-31 12:20:44

如何获取UITableView中cell的frame值的相关文章

UITableView中cell里的UITextField不被弹出键盘挡住

UITableView中cell里的UITextField不被弹出键盘挡住    本人视频教程系类   iOS中CALayer的使用   效果如下: 源码: EditCell.h 与 EditCell.m // // EditCell.h // Cell // // Created by YouXianMing on 14/12/18. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import <UIKit/UIKit

用适配器模式处理复杂的UITableView中cell的业务逻辑

用适配器模式处理复杂的UITableView中cell的业务逻辑 适配器是用来隔离数据源对cell布局影响而使用的,cell只接受适配器的数据,而不会与外部数据源进行交互. 源码: ModelCell.h 与 ModelCell.m // // ModelCell.h // Adapter // // Created by XianMingYou on 15/2/10. // Copyright (c) 2015年 XianMingYou. All rights reserved. // #im

UITableView中cell点击的绚丽动画效果

UITableView中cell点击的绚丽动画效果   本人视频教程系类   iOS中CALayer的使用   效果图: 源码: YouXianMingCell.h 与 YouXianMingCell.m // // YouXianMingCell.h // CellAnimation // // Created by YouXianMing on 14/12/27. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #imp

jsp页面传值-怎么获取url中?后面的值

问题描述 怎么获取url中?后面的值 例如:我的a.jsp页面上:超链接地址里有个 href="b.jsp?userName="你好" 那我在b.jsp页面中怎么获取这个userName的值 解决方案 html的方式可以location.search可以获取到?以及以后的数据. java方式(因为jsp内部可以使用java代码): request.getParameter("userName"); 解决方案二: 获取url后面的文件名如何获取URL后面锚点

jsp问题-JSP中如何获取select中每个oiption的值(不管选中与否)

问题描述 JSP中如何获取select中每个oiption的值(不管选中与否) 我的select里面的option是动态添加的,且option都没有name,仅有text和value 解决方案 没有ID?没有NAME 都没有一个唯一标识,如果是只是一个还好获取,多个就会出现混乱的情况 解决方案二: jsp获取还是js获取??

PHP在弹框中获取foreach中遍历的id值并传递给地址栏

1.php有时候我们需要再弹框中获取foreach中遍历的数据(例如id),在弹框中点击按钮并传递给地址栏跳转.那么应该怎么做呢. 2. 点击取现按钮,如果没有设置密码->弹框 3. 点击去设置,把用户名通过地址栏传递给别的页面. 4.使用onclick事件,把参数charge传递给function函数.function为弹窗函数. 5. 把username值传递过来.并给"去设置"赋值herf属性. 6. <div class="mask" >&

winform chart控件,通过什么事件能获取chart中选中区域的值?如图

问题描述 如图阴影区域是我选中的区域,想获取区域中point的值,用啥事件? 解决方案 本帖最后由 hellomahao 于 2015-09-24 12:41:23 编辑解决方案二:大家对chart控件使用的较少么?平时出图表都用第三方?发chart疑问的贴都没人回答..自己研究出来了,通过调用Chart的SelectionRangeChanged可以得到选区范围内的数值.我要做的是展示一系列数据,并提供给用户自己分析异常数据,通过选取一定范围内的异常数值显示相关数据.自己给自己结贴了..解决方

如何获取Repeater中文本框的值?

问题描述 <asp:RepeaterID="Repeater2"runat="server"><HeaderTemplate><tablewidth="100%"border="0"cellpadding="1"cellspacing="1"style="background-color:Gray"height:141;">

Javascript 获取Repeater中hidden Field 的值

问题描述 如何才能使用Javascript获取Repeater中hiddenField的值?首先点选Checkbox,然后获取相应的行的值,如hiddenfield控件绑定的id.Repeater如下:<asp:RepeaterID="rptList"runat="server"><HeaderTemplate><tablewidth="100%"border="0"cellspacing=&qu