2016-10-08 16 views
0

私は実際に動作するカスタムUIを持っていますが、うまく動作しないuiviewのすべてが動作するものと同じに設定されていると思います。ここでは、コードは次のようになります。カスタムUIViewのラベルとアニメーションがビューコントローラ内に表示されない

protocol SessionDisplayViewDelegate: class 
{ 
    func homeButtonTapped() 
} 

class SessionDisplayView: UIView 
{ 

@IBOutlet var view: UIView! 


@IBOutlet weak var accountImage: UIButton! 

@IBOutlet weak var mySKView: SKView! 
@IBOutlet weak var sessionTitle: UILabel! 

weak var delegate: SessionDisplayViewDelegate? 
required init(coder aDecoder: NSCoder) 
{ 
    super.init(coder: aDecoder)! 
    commonInitialization() 

} 

override init(frame: CGRect) { 
    super.init(frame: frame) 
    commonInitialization() 
} 

func commonInitialization() 
{ 
    Bundle.main.loadNibNamed("SessionDisplayView", owner: self, options: nil) 
    self.addSubview(self.view) 


    //accountImage = UIImage(data: ShareData.sharedInstance.accounts[ShareData.sharedInstance.indexOfCurrentAccount].picture!, scale: 1.0) 

} 

func onView() 
{ 
    let curScene = MyScene(size: mySKView.bounds.size) 
    curScene.scaleMode = SKSceneScaleMode.aspectFill 
    mySKView.presentScene(curScene) 
    let myImage = UIImage(data: (ShareData.sharedInstance.accounts[ShareData.sharedInstance.indexOfCurrentAccount]?.picture!)! as Data, scale: 0.5) 

    accountImage.setImage(myImage, for: UIControlState()) 
    sessionTitle.text = ShareData.sharedInstance.accounts[ShareData.sharedInstance.indexOfCurrentAccount]?.name 
    var myTest = sessionTitle.text 
    self.view.setNeedsDisplay() 

} 

@IBAction func homeButtonTouched(_ sender: UIButton) 
{ 
    delegate?.homeButtonTapped() 
} 
} 

私はself.view.setNeedsDisplayは()私はちょうどそれを動作させるためにしようとしているcalled-する必要があることを知りません。タイトルの変数が変更されても、タイトルは変更されません。これを確認して、それが動作しています。ラベルと変数の間に接続の問題があるか、View ControllerがView Controllerを変更するための更新信号を受け取っていません。私はどちらがどれであるかを決める方法がわからない。これを修正する方法に関するアイデアは深く感謝します。 ViewControllerコードは次のとおりです。

class SessionDisplayViewController: UIViewController, SessionDisplayViewDelegate 
{ 

@IBOutlet weak var mySessionView: SessionDisplayView! 
func homeButtonTapped() 
{ 
    self.performSegue(withIdentifier: "ReturnHome", sender: self) 
} 
override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view. 
    mySessionView.onView() 
    mySessionView.sessionTitle.text = "Test" 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
override var shouldAutorotate : Bool { 
    if (UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft) || (UIDevice.current.orientation == UIDeviceOrientation.landscapeRight) || (UIDevice.current.orientation == UIDeviceOrientation.unknown) 
    { 
     return true 
    } 
    else 
    { 
     return false 
    } 
} 

override var supportedInterfaceOrientations : UIInterfaceOrientationMask { 
    return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown] 
} 
override var preferredStatusBarStyle : UIStatusBarStyle 
{ 
    return UIStatusBarStyle.lightContent 
} 
} 

UIViewを更新する方法についてのご意見やご提案は大歓迎です。ありがとう。

敬具、
ショーン

答えて

0

はどのようにあなたのカスタムビューは、あなたのルートビューに追加しますか?コードから、またはxib/storyboardから? xib/storyboardでそれを行った場合は、カスタムビュークラスでawakeFromNibメソッドをオーバーライドし、その内部にcommonInitializationを呼び出す必要があります。 init()メソッドは、コードでビューを作成する場合にのみ呼び出されました。

+0

私はこれを試して助けませんでした。それは何とかビューコントローラが壊れてしまったことが判明しました。私はそれを削除して再作成し、それが機能しました。私はなぜか分からない。 –

関連する問題