UIView.animateWithDuration を使用するビューのサブビューとして UITableView をプログラムで追加して、ボタンが 1 つのポイントからフル ウィンドウにクリックされたときにビューを展開します。基本的には、点から始まり、アニメーションでフル サイズに拡大するボックスです。テーブルにセルを入力するのに苦労しています。最初はセルを作成していたのですが、アニメーションが終わってすぐに消えてしまい、いじってみたらアニメーションが終わってもセルが残るようになりましたが、タップするとセルが消えてしまいます。ここで何が起こっているのかわかりません。誰か助けてくれませんか?
これが私のコードです。コードを読みやすくするために、この問題に関係ないと思われるものを削除したことに注意してください。
class PokerLogSelectionView: UIViewController {
let logSelectionTableViewController = LogSelectionTableViewController()
let logSelectionTableView = UITableView()
// Irrelevant class variables removed
init(btn : PokerLogSelectionButton){
// Irrelevant view initialization code removed
// Display the subviews
self.displayLogListScrollView()
}
func displayLogListScrollView() {
// Frame is set to (0,0,0,0)
let frame = CGRect(x: self.subviewClosed, y: self.subviewClosed, width: self.subviewClosed, height: self.subviewClosed)
logSelectionTableView.delegate = self.logSelectionTableViewController
logSelectionTableView.dataSource = self.logSelectionTableViewController
// Set the frame of the table view
logSelectionTableView.frame = frame
// Give it rounded edges
logSelectionTableView.layer.cornerRadius = 10
// Remove the cell divider lines
logSelectionTableView.separatorStyle = UITableViewCellSeparatorStyle.None
logSelectionTableView.backgroundColor = logSelectionViewContentScrollViewColor
self.view.addSubview(logSelectionTableView)
//self.logSelectionTableView.reloadData()
//self.addChildViewController(logSelectionTableViewController)
}
override func viewDidAppear(animated: Bool) {
// Create animation
let timeInterval : NSTimeInterval = 0.5
let delay : NSTimeInterval = 0
UIView.animateWithDuration(timeInterval, delay: delay, options: UIViewAnimationOptions.CurveEaseOut, animations: {
// Irrelevant code removed
// Set the size and position of the view and subviews after the animation is complete
self.view.frame = CGRect(x: self.frameXopen, y: self.frameYopen, width: self.frameWopen, height: self.frameHopen)
self.logSelectionTableView.frame = CGRect(x: self.subviewXopen, y: self.svYopen, width: self.subviewWopen, height: self.svHopen)
}, completion: { finished in
self.addChildViewController(self.logSelectionTableViewController)
})
}
}
class LogSelectionTableViewController : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(LogSelectionCell.self, forCellReuseIdentifier: "logCell")
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pokerLibrary.logNames.count
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 20
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Selected row: \(indexPath.row)")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell : LogSelectionCell = self.tableView.dequeueReusableCellWithIdentifier("logCell") as? LogSelectionCell {
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.textLabel!.text = pokerLibrary.logNames[indexPath.row].name
return cell
}
fatalError("Could not dequeue cell of type 'LogSelectionCell'")
}
}
注: アニメーションが完了すると、テーブル ビューが表示されます。バックグラウンド ビューのビューとは色が異なり、テーブル ビューは消えず、セルだけが表示されます。セルが 1 つあると予想されます。セクション 0 の行数を出力すると、常に 1 が返されます。
助けてくれてありがとう!
編集:
セルが消える前のビュー階層のスクリーンショットを次に示します。
これは、セルをタップして非表示にした後のビュー階層のスクリーンショットです。
カスタム セルの touchesBegan メソッドをオーバーライドし、そのスーパークラス メソッドを呼び出しませんでした。これにより、セルをタップするとセルが消えなくなりましたが、tableView をスクロールするとセルが消えます。