2016-03-02 82 views
1

大家好我已经采取了视图控制器,并迅速iOS中迅速自定义视图网点未在视图控制器工作

一个自定义视图的ViewController

import UIKit 
class ViewController: UIViewController { 
var genderView : GenderOptionView! 

override func viewDidLoad() { 
    super.viewDidLoad() 

loadGenderCustomView() 
} 

func loadGenderCustomView() { 
genderView = GenderOptionView(frame: CGRectMake(0,0,rectIs.size.width * 0.95, rectIs.size.height * 0.355)) { (ScreeenType) ->() in 
     if(ScreeenType == 0) 
     { 
      print("Show Gender"); 
      //self.ShowLoginScreen() 
     } 
    }; 

    self.view.addSubview(genderView) 
} 
} 

自定义视图

import UIKit 
class GenderOptionView: BaseView { 

//static let sharedGenderOptionViewInstance = GenderOptionView() 

@IBOutlet weak var maleImgView: UIImageView! 
@IBOutlet weak var maleBtn: UIButton! 
@IBOutlet weak var maleLbl: UILabel! 
internal init(frame: CGRect, OnActions:(ScreeenType:NSInteger) ->()){ 

    super.init(frame: frame) 

    let myView = NSBundle.mainBundle().loadNibNamed("GenderOptionView", owner: self, options: nil)[0] as! UIView 

    self.frame = CGRectMake(frame.origin.x + 6,315,self.bounds.width,myView.bounds.height) 

    myView.frame = frame 
    //myView.backgroundColor = UIColor.greenColor() 
    //self.backgroundColor = UIColor.yellowColor() 

    OnActionsRef = OnActions; 
    self.addSubview(myView) 

    self.maleBtn.alpha = 0.0// I am getting here.. bad excess and in console fatal error: unexpectedly found nil while unwrapping an Optional value 
} 
} 

我在最后一行出现错误..错误的超额和控制台致命错误:意外地发现零,同时展开一个可选值 在视图中加载视图controll呃

和基础视图是

import UIKit 
class BaseView: UIView { 

var OnActionsRef : (ScreeenType:NSInteger) ->() = {_ in }; 
} 
+0

是'maleBtn'与正确链接故事情节? –

+0

是的..我做的正确 – Sunil

回答

1

使用

myview.maleBtn.alpha = 0.0 

你不是装在自己笔尖,要装载在MyView的

+0

让我知道如果你仍然得到错误,如果它的工作请批准,以便任何人都可以使用它 – techloverr

相关问题