Ios – how to add textfield in tableview cell(each row) and set tag to each textfield to access it’s text


How can i add textfield in tableview cell (on each row).
This textfield will be in middle of each row.
And also set Tag on each textfield of cell to access their text.

Best Solution

Of course you can, a small example:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
    if(cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"] autorelease];

        UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(0, (cell.contentView.bounds.size.height-30)/2, cell.contentView.bounds.size.width, 30)];
        [cell.contentView addSubview:tv];
        [tv setDelegate:self];
        tv.tag = indexPath.row;

    return cell;

- (void)textViewDidEndEditing:(UITextView *)textView {
    NSLog(@"%d", textView.tag);

    [textView resignFirstResponder];