将textfield添加到tableviewheader [英] add textfield to tableviewheader

查看:165
本文介绍了将textfield添加到tableviewheader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文本字段添加到标题视图中。我无法弄清楚为什么我看不到我的文本域。当我使用标签时,它可以很好地工作。

I am trying to add textfield to header view. I could not figure out why I can't see my textfield. When I use a label it works perfectly.

以下是代码:

-(UIView*) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
       UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(40, 0, self.view.frame.size.width - 70, 30)];
    UITextField *sectionTitleTF1 = [[UITextField alloc] initWithFrame:CGRectMake(58, 0, 500, 30)];
    sectionTitleTF1.backgroundColor = [UIColor whiteColor];
    [sectionTitleTF1 becomeFirstResponder];
    [tableHeaderView addSubview:sectionTitleTF1];
return tableHeaderView;

}

谢谢

推荐答案

试试这个,

  You can adjust view, textfield frame based on your device ipad or iphone




 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30.0;
}

-(UIView*) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(40, 0, self.view.frame.size.width - 70, 30)];
tableHeaderView.backgroundColor =[UIColor grayColor];
UITextField *sectionTitleTF1 = [[UITextField alloc] initWithFrame:CGRectMake(58, 0, 500, 30)];
sectionTitleTF1.backgroundColor = [UIColor whiteColor];
[sectionTitleTF1 setBackgroundColor:[UIColor whiteColor]];
[sectionTitleTF1 setFont:[UIFont boldSystemFontOfSize:15]];
[sectionTitleTF1 setBorderStyle:UITextBorderStyleLine];
[sectionTitleTF1 setTextAlignment:UITextAlignmentCenter];
[sectionTitleTF1 setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
[sectionTitleTF1 becomeFirstResponder];
[tableHeaderView addSubview:sectionTitleTF1];
return tableHeaderView;
}

这篇关于将textfield添加到tableviewheader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆