Objective c 快速编程
我是swift语言的初学者。我得到这个错误:Objective c 快速编程,objective-c,ios7,swift,Objective C,Ios7,Swift,我是swift语言的初学者。我得到这个错误: Error: Any object does not have member named subscript. 有人能给出解决办法吗 我的代码: controller! = UIAlertController(title: "Welcome", message: "Hi...", preferredStyle: .Alert) let action = UIAlertAction(title: "Please en
Error: Any object does not have member named subscript.
有人能给出解决办法吗
我的代码:
controller! = UIAlertController(title: "Welcome", message: "Hi...", preferredStyle: .Alert)
let action = UIAlertAction(title: "Please enter atleat 10 characters", style: UIAlertActionStyle.Default, handler: {[weak self] (paramAction:UIAlertAction!) in
let userName = self!.controller!.textFields[0].text
println("your username is \(userName)")
})
controller!.addTextFieldWithConfigurationHandler({(textField:UITextField!) in
textField.placeholder = "XXXXX-XXXXX"
})
用这个
var controller = UIAlertController(title: "Welcome", message: "Hi...", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Please enter atleat 10 characters", style: UIAlertActionStyle.Default, handler: {[weak self] (paramAction:UIAlertAction!) in
var userName = controller.textFields?
println("your username is \(userName)")
})
controller.addTextFieldWithConfigurationHandler({(textField:UITextField!) in
textField.placeholder = "XXXXX-XXXXX"
})
controller.view.center = self.view.center
self.view .addSubview(controller.view)
如何声明变量
textFields
?实际上,该代码在cook book中。我只是打字。我犯了那个错误。。你能给出一个正确的代码吗??
let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self](paramAction:UIAlertAction!) in
if let textFields = self!.controller?.textFields{
let theTextFields = textFields as [UITextField]
let userName = theTextFields[0].text
println("Your username is \(userName)")
}
})