【发布时间】:2014-12-29 21:21:06
【问题描述】:
在下面的removeTextFieldObserver 函数中,我收到错误“[NSObject : AnyObject]?”没有一个名为‘下标’的成员”。如果是字典,它肯定应该有一个下标吗?
func showSimpleAlert()
{
let title = NSLocalizedString("A Short Title is Best", comment: "")
let message = NSLocalizedString("A message should be a short, complete sentence.", comment: "")
let cancelButtonTitle = NSLocalizedString("OK", comment: "")
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
// Create the action.
let cancelAction = UIAlertAction(title: cancelButtonTitle, style: .Cancel) { action in
NSLog("The simple alert's cancel action occured.")
}
// Add the action.
alertController.addAction(cancelAction)
presentViewController(alertController, animated: true, completion: nil)
}
func removeTextFieldObserver()
{
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextFieldTextDidChangeNotification, object: alertController.textFields[0])
}
【问题讨论】:
-
textFields是什么?你是怎么申报的? -
textFields[0],它是 alertController 在索引 0 处的默认属性
-
试试。 var arr = alertController.Textfield?作为 NSArray 然后 arr[0]