views:

62

answers:

3

hi all, i have created an iPhone application with a view based .. the problem is i want to load a table view on click of button how can i do it? i tried..

initWithNibName:@"xibfile" bundle:[NSBundle mainBundle]...

but table view is not loading wat to do?

A: 

Assuming you are using a navigation controller, in the code related to the action associated to your button, do something like

YourTableViewController *yourTableViewController = [[YourTableViewController alloc] initWithNibName:@"YourTableViewController" bundle:nil];
[self.navigationController pushViewController:yourTableViewController animated:YES];
[yourTableViewController release];

Otherwise, you may present your table view controller as a modal view.

unforgiven
He is using a view based application
Madhup
A: 

If you're asking how to load a view controller, the pattern looks something like this:

MyViewController* myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
Shaggy Frog
A: 

If you're not using or directly subclassing UITableViewController I'm assuming that your UITableView is an ivar of your UIViewController subclass.

If this is the case you'll need to assign your UIViewController subclass to be the UITableView's delegate and set your UIViewController to conform to the UITableViewDelegate protocol. Also you'll need to create a datasource object that conforms to the UITableViewDataSource protocol. Then set the UITableView's data source to be that UITableViewDataSource object.

So in your header file you'll have:

@class SomeDataSource;
@interface{
UITableView *tableView;
SomeDataSource *dataSource;
}

Then in your implementation block, probably in viewDidLoad, you should include:

tableView.delegate = self;
tableView.dataSource = dataSource;
Dustin Pfannenstiel