简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM