Tutorial :iPhone app development : How can i get a table view in which whn i click on a cell a text view should expand just below that cell…?


How can i get a table view in which whn i click on a cell a text view should expand just below that cell it should look like clicking on a button an it will create a text view in between clicked button and its below button...

i m trying to create a pictorial view...

tabel view:    button 1   >    button 2   >    button 3   >          table view:    button 1 >    button 2 v  __________  .    .    . text view    .  ----------  button 3 >  

plz solve my problem i m new for iphone app development....


I dont think that this can be done the way u want it, because once the TableView is loaded it is loaded, and if even if you manage to push some extra cells in between, the Table View will not change until it is loaded again. TableView is loaded in two scenarios i.e 1. When Loading the view 2. While scrolling within the TableView.

my advice is to show a popup window kind of thing...


- (UITableViewCell *)valueForSelectedRow {      UITableViewCell *cell = [self.AccountTable cellForRowAtIndexPath:[self.AccountTable indexPathForSelectedRow]];      return cell;  }    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {      // Get value      UITableViewCell *cell = [self valueForSelectedRow];      cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);      UITextview *txtview = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 25.0f)] autorelease];     [cell addSubview:txtview];      [cell sizeToFit];      //...  



You might insert a row just under the selected one.

The steps are:

  1. Create an instance of NSIndexPath for the new row
  2. Update your datasource (insert a special object containing the information for your text view). Notice that the datasource object must be mutable (e.g. NSMutableArray).
  3. Insert new row to the table

Sample implementation may look like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    [tableView deselectRowAtIndexPath:indexPath animated:YES];      // 1    NSIndexPath *newRowIndexPath = [NSIndexPath indexPathForRow:(indexPath.row + 1) inSection:indexPath.section];      // 2 (datasource has to be mutable)    [self.datasource insertObject:[NSDictionary dictionaryWithObject:@"THE_TEXT_FOR_YOUR_TEXTVIEW"] atIndex:newRowIndexPath.row];      // 3    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newRowIndexPath] withRowAnimation:UITableViewRowAnimationBottom];  }  

Notice that in addition to this code you will have to treat the "special" row differently in tableView:cellForRowAtIndexPath: method...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »