我会在UIView
里放一个UITableView
。我创建了一个 XIB,其中我有一个表视图。
#import <UIKit/UIKit.h>
@interface PointsViewController : UIViewController <UITableViewDelegate>
{
IBOutlet UITableView *tableView;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
[tableView setDelegate:self];
}
我从另一个类实例化PointViewController
类,并通过按钮将其添加到UINavigationBar
:当我单击按钮时,PointsViewController
'view(tableView)将打开。但事实并非如此。我错过了什么?我还尝试将PointsViewController作为UITableViewController
的子类,但是没有显示UITableView
。
您还需要使 ViewController 成为 UITableViewDataSource 的委托。
@interface PointsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *tableView;
}
@end
。并支持相应的方法。
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
您还需要挂接表的数据源并委托给文件的所有者。 否则,视图控制器不知道要向哪个表发送响应。
在 XIB 中,选择表并打开连接检查器。 然后将数据源旁边的"加号"拖到文件的所有者以建立连接。 对委托和表的引用出口执行相同的操作。