如何将静态TableView添加到ViewController

如何在不使用容器和UITableViewController的情况下将静态TableView添加到ViewController?

我认为这是可能的前一段时间,但现在最新的xCode故事板和iOS 7不是。 没有有效答案的类似的问题在这里 – iOS 7的UIView更改为UITableView我的表有一点区别 – 我尝试添加一个静态数据。 我在程序启动时遇到应用程序崩溃。 程序崩溃,如果我只设置数据源。 如果我取消链接数据源并保持代理和sockets程序启动没有警告,但与空单元格。 备注 – 故事板在没有我的协助的情况下将ViewController的命名从ViewController更改为ViewView的TableViewController。 我认为这是在添加IBOutlet UITableView * myTableView之后发生的。 为什么这样,是什么意思?

在UITableViewDataSource中有2个必需的方法:

– tableView:cellForRowAtIndexPath: required method – tableView:numberOfRowsInSection: required method 

这意味着在MYTableViewController中,你必须实现像这样的例子(3个单元格Test1,Test2和Test3):

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MyStaticCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"Test%d",indexPath.row+1]; return cell; }