是的,你可以在UIViewController中有静态表格视图内容。
所有你需要做的是:
- 创建表的静态细胞在Interface Builder和设计他们自己喜欢的方式。
- 制作所述的UIViewController实现表视图的数据源和委托:
@interface MyViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
- 连接表视图的界面生成器代表且dataSource到视图控制器
- 实施-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
返回你的细胞数量。 (例如return 10
,这样做很简单)
- 将接口生成器中的IBOutlets连接到代码中。 重要提示:确保它们是strong
,弱不起作用。例如@property (strong, nonatomic) IBOutlet UITableViewCell *myFirstCell;
-Implement -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
在索引路径返回正确的单元格。例如:
int num = indexPath.row;
UITableViewCell *cell;
switch (num) {
case 0:
cell = self.myFirstCell;
break;
case 1:
cell = self.mySecondCell;
break;
}
return cell;
如果您应用所有这些步骤,您应该有工作的静态单元格适用于单元格不多的表格。完美的桌子,你有几个(可能不超过10-20就足够了)的内容。几天前我跑了同样的问题,我确认它的工作原理。更多信息请查看此处:Best approach to add Static-TableView-Cells to a UIViewcontroller?
你的问题解决了吗?请检查我的答案 –