我有一個主ViewController是表視圖控制器。我有兩個筆尖文件。其中一個筆尖包含一個表格視圖。我想保留該表格視圖中的數據。我很困惑如何將UItable視圖委託和數據源從nib文件返回到mainView。Swift:返回UItable視圖代表和數據源
這裏是我的代碼:
var participationList : ["Apple","Dog","cat","Mat"]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0
{
//first cell
}
if indexPath.row == 1
{
let cell : ActivitySecondTableViewCell = (NSBundle.mainBundle().loadNibNamed("ActivitySecondTableViewCell", owner: self, options: nil).first as? ActivitySecondTableViewCell)!
cell.textLabel?.text = self.participationList[indexPath.row]
return cell
}
let cell : ActivitySecondTableViewCell = (NSBundle.mainBundle().loadNibNamed("IncentiveActivitySecondTableViewCell", owner: self, options: nil).first as? IncentiveActivitySecondTableViewCell)!
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
這是我的主表視圖控制器,我從這裏返回細胞。細胞清晰地顯示在這裏。而ActivitySecondTableViewCell裏面包含Table視圖。
這是我的筆尖:
class ActivitySecondTableViewCell: UITableViewCell,UITableViewDelegate {
@IBOutlet weak var CellTableView: UITableView!
override func awakeFromNib() {
super.awakeFromNib()
self.CellTableView.delegate = self
// Initialization code
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Required Health Activities for 2017"
}
func tableView(tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
if let headerTitle = view as? UITableViewHeaderFooterView {
headerTitle.textLabel?.textColor = UIColor.redColor()
}
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我既看不到在Activitysecond細胞的稱號也不是data.How我可以achive他們?
我怎麼可以給numberOfRows到secondTableViewCell使用,?? – Sam
在你的ActivitySecondTableViewCell開始輸入numberOfRows,這樣你可以定義numberOfRows。如果建議不會到來,請使用UITableViewDataSource繼承ActivitySecondTableViewCell,然後檢查。 –
你能解決這個問題嗎? –