Iam trying to develop UITableView with a multiline textfield in its cell. I created UITableView and cell programmatically and at this moment i added one normal UITextField but i really want something like whats app chat typing field so when i type more characters it will increase its height and UITableViewCell height automatically. (pls check attached image)
My UITableView Delegate methods
- (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;
}
Even it tried this code but its not working, when i run with this changes UITableView Cell was empty. Tried the same, but not working Pls suggest answer.
Attached images