To do this, you need to embed it in your UITableViewCell. But there is no need to create a custom cell. Here is the basic idea of โโwhat you want to do:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; UITextView *comment = [[UITextView alloc] initWithFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, tableView.rowHeight)]; comment.editable = NO; comment.delegate = self; [cell.contentView addSubview:comment]; [comment release]; } return cell; }
You will of course need to set your rowHeight if you don't need the standard 44pt height that comes with the cell. And if you need real cells, you need to add your own logic, so that only the cell you want is a textView, but this is the main idea. The rest is yours to customize your fitting. Hope this helps
EDIT: To get around TextView to get into your cell, there are two ways to do this.
1) you can create your own textView class and rewrite touchhesBegan to send a super message:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; }
this will send touch events to its supervisor, which will be your tableView. Given that you don't want to create custom UITableViewCells, I think you probably don't want to create your own textView class either. This leads me to option 2.
2) when creating a textView, delete comment.editable = NO; . We need to keep it editable, but fix it in the delegate method.
In your code, you will need to insert the textView delegate method, and we will do all our work from there:
EDIT: Modifying this code for use with the UITableViewController
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
If this is not what you wanted, just let me know and we will take you apart.
justin
source share