views:

498

answers:

1

Hey,

I'm creating a UINavigationController based app. And in the first view i have a UITableViewController.

I want to have the same behaviour that the Contacts App have. 1) User select contact 2) System show contact details 3) User selects que back button 4) System returns to the tableview, and fadeout the cell

I can only do this if i create a UIViewController, and a xib with a UITableView. And then add the following code:

- (void)viewDidAppear:(BOOL)animated{
    if ([self.mytableView indexPathForSelectedRow] != nil){
        [self.mytableView deselectRowAtIndexPath:[self.mytableView indexPathForSelectedRow] animated:YES];
    }
}

I really don't want to have a xib only for this. So is it possible to do it in with a UITableViewController?

+1  A: 

Yes. A UITableViewController is a subclass of UIViewController so you can overide the viewDidAppear:animated method however you wish.

If you want to create the UITableViewControl programmatically (i.e. without loading it from a nib), you'll have to manually configure the UITableView. See the following in the UITableViewController class reference:

  • If a nib file is specified via the initWithNibName:bundle: method (which is declared by the superclass UIViewController), UITableViewController loads the table view archived in the nib file. Otherwise, it creates an unconfigured UITableView object with the correct dimensions and autoresize mask. You can access this view through the tableView property.
  • If a nib file containing the table view is loaded, the data source and delegate become those objects defined in the nib file (if any). If no nib file is specified or if the nib file defines no data source or delegate, UITableViewController sets the data source and the delegate of the table view to self.
Jason Jenkins
Yes, i know, but when i override the viewDidAppear:animated to deselect the row it won't work, because the UITableViewController already deselects the row, but don't show the row to the user.Sorry for the poor english...
Baltas
Perhaps you could try to use `scrollToRowAtIndexPath:atScrollPosition:animated:` to make the selected row visible before deselecting it. You could try doing that either above the call to `deselectRowAtIndexPath:animated:` in `viewDidAppear`or perhaps earlier in `viewWillAppear`.
Jason Jenkins
Ok i found the problem.In the viewWillAppear i have the [self.tableView reloadData] because i may change the content of the my data.And if i test the [self.tableView indexPathForSelectedRow] before the reloadData, i get nil so that didn't work.If i don't call the reloadData method, the cell fadeout correctly, but my data may not be up to date, so is there other way to achieve this?
Baltas