iOS解决表格中TextField,TextView编辑时,输入框被键盘遮挡的问题
2024-08-31 00:23:28
方法1:在原来的 UIViewController 内部再添加一层 UITableViewController
代码如下 :
//
// ViewController.m
// 键盘遮挡问题
//
// Created by 思 彭 on 17/2/4.
// Copyright © 2017年 思 彭. All rights reserved.
// #import "ViewController.h"
#import "MyCell.h" static NSString *const identify = @"cell"; @interface ViewController () <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad];
self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView]; [self.tableView registerClass:[MyCell class] forCellReuseIdentifier:identify]; UITableViewController *tableViewVc = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
tableViewVc.tableView = self.tableView;
[self addChildViewController:tableViewVc];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [tableView dequeueReusableCellWithIdentifier:identify forIndexPath:indexPath];
return cell;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
方法2:监听键盘通知,在键盘出现或消失的时候修改tableView 的 contentInset 和 scrollIndicatorInsets
最新文章
- 初识JAVA之OOP
- FingerGestures for Unity3D
- 网络拥塞控制(三) TCP拥塞控制算法
- Vue.2.0.5-表单控件绑定
- BZOJ 3207 花神的嘲讽计划Ⅰ(函数式线段树)
- Java知识总结--数据库
- 39一个可以让你受益HTML5课程
- Git 一些常见的命令
- hive的表的基本操作
- JavaScript事件与例子
- 洛谷P4180 [Beijing2010组队]次小生成树Tree(最小生成树,LCT,主席树,倍增LCA,倍增,树链剖分)
- How far away ? HDU - 2586 【LCA】【RMQ】【java】
- Ubuntu 16.04安装Docker-CE
- web-worker 的使用
- Hibernate的注解和检索
- Oracle 11g透明网关连接Sqlserver
- STL算法总览(部分)
- Android 开发 VectorDrawable 矢量图 (二)了解矢量图属性与绘制
- loj#2038. 「SHOI2015」超能粒子炮・改
- Java 中>;>;和>;>;>;的区别
热门文章
- Glass Carving CodeForces - 527C (线段树)
- java8学习之Stream实例剖析
- Tableau Sheet中的操作
- WebView net::ERR_CLEARTEXT_NOT_PERMITTED&;&;net::ERR_INTERNET_DISCONNECTED
- 拒绝被坑!如何用Python和数据分析鉴别刷单!?
- golang之 Array(数组)
- yaml格式介绍
- Qt5多线程
- 【NOIP2017提高A组模拟10.7】Adore
- nodejs之express入门