【发布时间】:2015-11-03 08:26:10
【问题描述】:
我正在尝试在其单元格中开发具有多行文本字段的 UITableView。 我以编程方式创建了 UITableView 和单元格,此时我添加了一个普通的 UITextField,但我真的想要什么应用程序聊天输入字段之类的东西,所以当我输入更多字符时,它会自动增加其高度和 UITableViewCell 高度。 (请查看附件图片)
我的 UITableView 委托方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [selectedTabFields count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell= [tableView1 dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil)
{
cell = [[homeCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
[cell.contentView addSubview:[self getIntegerTextfield:indexPath.row]];
}
return cell;
}
//Integer Textfield
-(UITextField *)getIntegerTextfield:(NSUInteger)index{
UITextField *textField= [[UITextField alloc] initWithFrame:CGRectMake(15,40,cell.frame.size.width-30,cell.frame.size.height)];
textField.placeholder=@"Text here";
textField.tag=index;
textField.delegate=self;
textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
textField.textAlignment=UITextAlignmentLeft;
textField.font= [UIFont fontWithName:@"Helvetica-Neue Light" size:14];
textField.textColor=[UIColor darkGrayColor];
textField.backgroundColor=[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1];
return textField;
}
即使它尝试了此代码但它不起作用,当我使用此更改运行时 UITableView 单元格是空的。 Tried the same, but not working 请建议答案。
附加图片
【问题讨论】:
-
如果你想要多行那么你需要添加 UITextView 因为 UITextField 只有一行。
标签: ios objective-c uitableview uitextfield uitextview