Reputation: 604
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.
Upvotes: 3
Views: 5927
Reputation: 1691
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];
}
...
Upvotes: 4