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

     

  • 相关阅读:
    .Net中多线程类的使用和总结
    单例模式完整解析
    避免构造/析构函数调用虚函数(转)
    正则表达式
    序列化与反序列化
    数组的使用,指针的使用
    jmeter单接口和多接口测试
    HTML5 input placeholder 颜色修改
    h5动画效果总结
    8月份月度反思--做一个快乐的程序员
  • 原文地址:https://www.cnblogs.com/pengsi/p/6366376.html
Copyright © 2011-2022 走看看