gdm
gdm

Reputation: 7978

UITableView inside a UIView

I would put an UITableView inside a UIView. I created a XIB where I have a tableView.

#import <UIKit/UIKit.h>

@interface PointsViewController : UIViewController <UITableViewDelegate>
{

  IBOutlet UITableView *tableView;
}
@end

- (void)viewDidLoad
{

 [super viewDidLoad];
 [tableView setDelegate:self];
}

I instantiate the PointViewController class from another class and add it to a UINavigationBar by means of a button:when I click the button, the PointsViewController'view (the tableView) shall open. But it does not. What am I missing? I tried also to make PointsViewController as a subclass of UITableViewController which works, but no UITableView is displayed.

Upvotes: 0

Views: 1059

Answers (2)

SeanK
SeanK

Reputation: 667

You need to also hook up the table's dataSource and delegate to the File's Owner. Otherwise the view controller doesn't know what table to send responses to.

In your XIB, select the table and open the Connection Inspector. Then drag the 'plus' sign next to dataSource to File's Owner to make the connection. Do the same for delegate and the table's referencing outlet.

Upvotes: 1

Snips
Snips

Reputation: 6773

You will also need to make your ViewController a delegate for UITableViewDataSource.

@interface PointsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
    IBOutlet UITableView *tableView;
}
@end

...and support the corresponding methods.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

Upvotes: 2

Related Questions