Xcode中使用Picker View和Segue, Size to fit content

05. April 2016 Swift 0

调整控件中的内容,会使内容和控件显示出现问题,快速适配 Editor->Size to fit content 可以快速使控件适配内容,亦或快捷键 command +=,当然,前提选择控件。

使用Picker View 需要实现三个方法,继承UIPickerViewDataSource,UIPickerViewDelegate

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{

return 1;// 列数

}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{

return lijians.count;  //行数

}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

return lijians[row];

}并且设置代理和数据源

 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == “A”{  //判断segue,用处极大,判断调转那个页面

let index = Picker.selectedRowInComponent(0)

var vc = segue.destinationViewController as! Second  //强制转换成Second,在前一页就可以给后一页赋值,很棒

vc.ss = flag


Leave a Reply

Your email address will not be published. Required fields are marked *