我正在尝试从用户那里获取USERNAME和PASSWORD并将它们放在一个字符串中。
import UIKit
class CustomCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var answer: UITextField!
var delegate: QuestionSelectorCellDelegate?
var pickOption: [String] = []
var pickerView:UIPickerView = UIPickerView()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
@IBAction func editBeginQuestionSelectorCell(sender: UITextField) {
pickerView = UIPickerView()
pickerView.delegate = self
// --- Thats what I added ---
pickerView.dataSource = self
let indexOfDefaultElement = 1 // Make sure that an element at this index exists
pickerView.selectRow(indexOfDefaultElement, inComponent: 0, animated: false)
sender.inputView = pickerView
}
func displayBlock(block: Block){
if block.answers != nil {
pickOption = block.answers! // block.answers! = ["blue","red","green"] for example
}
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickOption.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickOption[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if row < pickOption.count {
answer.text = pickOption[row]
delegate?.updateQuestionSelectorCell(self, rep: pickOption[row])
}
}
}
这是我的代码:
var id = "1"
var pw = "password"
但它创造了这个结果:
parser = NSXMLParser(contentsOfURL: NSURL(string : "http://blablabla.com/UNAME&PW")!)!
如何将"http://blablabla.com/\id\&\pw\"
和id
的值放在字符串中?
答案 0 :(得分:1)
对于swift中的Concat字符串,您有两个选择:
let completeURL = "http://blablabla.com/\(usernameVar)&\(passwordVar)"
let completeURL = "http://blablabla.com/" + usernameVar + "&" + passwordVar