是的,你可以在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?
你的問題解決了嗎?請檢查我的答案 –