2016-06-01 3 views
1

小さなウィンドウとして特定のノードをクリックするたびに、TableViewControllerをシーン内に表示します。私はそれを設定するためにTableViewControllerクラスを作成しました。ここSkScene内部の私のコードは次のとおりです。SKScene内のTableViewControllerを使用

 let table = Table() 
     let smallerRect = CGRectMake(100, 100, 200, 100) 
     let navRect = CGRectMake(0, 100, 200, 200) 
     let nav = UINavigationController(rootViewController: table) 
     nav.view.frame = navRect 
     let frameView = UIView(frame: smallerRect) 

     frameView.backgroundColor = UIColor.redColor() 
     table.view.frame = smallerRect 
     frameView.addSubview(nav.view) 
     self.view.addSubview(frameView) 

テーブルクラス:

import UIKit 

class Table: UITableViewController { 

    var names = ["name1", "name2", "name3"] 

    override func viewDidLoad() { 
    super.viewDidLoad() 

} 
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return names.count 
    } 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 

     cell.textLabel?.text = names[indexPath.row] 

     return cell 
    } 
} 

問題は、テーブルビューが含まれていることになってのUIViewが表示されますが、テーブル自体にはないということです。 助けてもらえますか、誰かが私が望むものを達成するためのよりよい方法を持っていても、私は感謝します。

答えて

0

フレームビューの境界に基づいて、navViews/tableviewフレームを設定する必要があります。

(0、0、200、200)となります。現時点では、テーブルがフレームビューのサブビューとして追加されると、それは100だけオフセットされます。したがって、フレームビューの範囲外に描画されます。

このようなものが多分あります。あなたのTableコードなしでこれで行くことに他にどこ知ることは難しい

let table = Table() 
    let smallerRect = CGRectMake(100, 100, 200, 100) 
    let navRect = CGRectMake(0, 0, 200, 200) 
    let nav = UINavigationController(rootViewController: table) 
    nav.view.frame = navRect 

    let frameView = UIView(frame: smallerRect) 
    frameView.backgroundColor = UIColor.redColor() 
    table.view.frame = frameView.bounds 

    frameView.addSubview(nav.view) 
    self.view.addSubview(frameView) 

+0

答えてくれてありがとうございますが、それはそうではありません。私は質問をTableクラスで更新しました。 – Abdou023

関連する問題