zoukankan      html  css  js  c++  java
  • iOS解决表格中TextField,TextView编辑时,输入框被键盘遮挡的问题

    方法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 20;
    }
    
    - (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

     

  • 相关阅读:
    Maven入门详解
    (二)从分布式一致性谈到CAP理论、BASE理论
    (一)从集中式到分布式
    四种MySQL存储引擎
    日期函数、时间函数总结(MySQL 5.X)
    SQL函数说明大全
    Java虚拟机1:什么是Java
    Java设计模式1:设计模式概论
    Linux概述
    Android 使用SharedPreference来进行软件配置的存取
  • 原文地址:https://www.cnblogs.com/pengsi/p/6366376.html
Copyright © 2011-2022 走看看