views:

376

answers:

1

I've got a Navigation iPhone app and it's "second level" controller is currently a UIViewController whose Nib contains a UIView. I made space at the top of the UIView for a navigation bar and then I added a tool bar on the bottom, on which I put a refresh button, a label, and an activity indicator. Last, but not least, I put a table view in the middle.

I connected everything up between the controller and the nib and made the File's owner connect to the UIView and the datasource and delegate for the UITableView contained by the UIView to refer to the File's owner and everything works fine.

But I can't figure out how to tell the table view to refresh.

I thought I could just put this in the code where I want the table to update:

[self.tableView reloadData];

But unless my second level controller is a UITableViewController that line of code won't compile. When I make my second level controller a UITableViewController, my app blows up when the second level controller gets loaded because the file's owner doesn't refer to a table view controller, and when I make the file's owner refer to the table view outlet instead of the view, things work except for the fact my tool bar on the bottom, along with its label and refresh button don't appear anymore.

I also tried simply adding

[self refresh];

in place of [self.tableview reloadData] but the code gets stuck in a loop refreshing itself.

How can I get this all working? I think I need to leave my second level controller as a UIViewcontroller but I still want to be able to get the UITableView it contains to update itself when I want it to.

+1  A: 

Why can't your second-level controller be a UITableViewController? It's a subclass of UIViewController to begin with, so you're not losing any functionality.

In any event, non-UITableViewController UIViewController classes don't have the tableView property you can call. You should instead hold on to the table view in your own ivar and call that. (You can even call it tableView; you just have to define it yourself.)

@interface MyViewController : UIViewController {
    UITableView *tableView;
}

@property(nonatomic,retain) IBOutlet UITableView *tableView;

- (void)myMethod;

@end
@implementation MyViewController

@synthesize tableView;

- (void)myMethod {
    [self.tableView reloadData];
}
Tim
Thank you very much. I'm pretty new to all this and didn't even think of simply adding an outlet to get to the table to tell it to redisplay. Perfect answer!
Dale