実際にUIViewControllerの代わりにtableViewを使用してUITableViewControllerを使用するのはなぜですか?
ヘッダビューを追加してからヘッダのフレームに応じてtableviewを追加してください。例えば
: `輸入のUIKit
クラスのViewController:のUIViewController、UITableViewDelegate、UITableViewDataSource { するvar fixedLabel:UILabel! var tableView:UITableView!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.tableView.frame = CGRectMake(0, self.fixedLabel.frame.maxY, self.view.frame.width, self.view.frame.height-70)
self.fixedLabel.frame = CGRectMake(0,0,self.view.bounds.width,70)
}
override func viewDidLoad() {
super.viewDidLoad()
self.fixedLabel = UILabel()
self.fixedLabel.backgroundColor = UIColor.blueColor()
self.fixedLabel.text = "This is a fixedLabel"
self.fixedLabel.textAlignment = .Center
self.tableView = UITableView()
self.tableView.delegate = self
self.tableView.dataSource = self
self.view.addSubview(fixedLabel)
self.view.addSubview(tableView)
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell")
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
}
cell?.textLabel?.text = "Your text"
return cell!
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
}テストとして '
、y'値 'に66を加えます。それは役に立ちますか? – rmaddy
'storyboard'を通して' tableViewController'を追加しましたか?もしそうなら、 'tableView'の最上部に' UIView'を追加することができます。 – Santosh
rmaddy、返事ありがとうございます。それは効果をもたらさなかった。 –