Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义表格单元格文本字段:没有被重用的表格单元格的索引路径Swift Xcode6 Beta 6_Ios_Xcode_Uitableview_Swift - Fatal编程技术网

Ios 自定义表格单元格文本字段:没有被重用的表格单元格的索引路径Swift Xcode6 Beta 6

Ios 自定义表格单元格文本字段:没有被重用的表格单元格的索引路径Swift Xcode6 Beta 6,ios,xcode,uitableview,swift,Ios,Xcode,Uitableview,Swift,当第一次从自定义表格单元格Nib显示using textfields时,我没有收到要重用的表格单元格的索引路径,Textfield委托方法都不起作用,但一旦退出Textfield并再次输入它,错误就不会显示,委托方法也会起作用 cellForRowAtIndexPath: if indexPath.row == 0 { var mailCell: mailTableCell = tableView!.dequeueReusableCellWithIdentifier("mailC

当第一次从自定义表格单元格Nib显示using textfields时,我没有收到要重用的表格单元格的索引路径,Textfield委托方法都不起作用,但一旦退出Textfield并再次输入它,错误就不会显示,委托方法也会起作用

cellForRowAtIndexPath:

if indexPath.row == 0 {
        var mailCell: mailTableCell = tableView!.dequeueReusableCellWithIdentifier("mailCell", forIndexPath: indexPath) as mailTableCell
        var nib: NSArray = NSBundle.mainBundle().loadNibNamed("mailTableCell", owner: nil, options: nil)
        mailCell = nib.objectAtIndex(0) as mailTableCell

        mailCell.textField.delegate = self
        mailCell.textField.tag = 1
        mailCell.separatorInset = UIEdgeInsetsZero

        return mailCell

    } else if indexPath.row == 1{
        var passCell = tableView!.dequeueReusableCellWithIdentifier("passCell", forIndexPath: indexPath) as passwordTableCell
        var nib: NSArray = NSBundle.mainBundle().loadNibNamed("passwordTableCell", owner: nil, options: nil)
        passCell = nib.objectAtIndex(0) as passwordTableCell

        passCell.textField.delegate = self
        passCell.textField.tag = 2
        passCell.textField.returnKeyType = UIReturnKeyType.Go
        passCell.separatorInset = UIEdgeInsetsZero

        return passCell

    } else {
        var buttonCell = tableView!.dequeueReusableCellWithIdentifier("loginCell", forIndexPath: indexPath) as buttonTableCell
        var nib: NSArray = NSBundle.mainBundle().loadNibNamed("buttonTableCell", owner: nil, options: nil)
        buttonCell = nib.objectAtIndex(0) as buttonTableCell

        buttonCell.separatorInset = UIEdgeInsetsZero
        buttonCell.label.tag = 3
        buttonCell.indicator.tag = 4

        return buttonCell
    }
viewDidLoad:

 override func viewDidLoad() {
    super.viewDidLoad()

    var mailCell = UINib(nibName: "mailTableCell", bundle: nil)
    var passCell = UINib(nibName: "passwordTableCell", bundle: nil)
    var loginCell = UINib(nibName: "buttonTableCell", bundle: nil)

    tableView!.registerNib(mailCell, forCellReuseIdentifier: "mailCell")
    tableView!.registerNib(passCell, forCellReuseIdentifier: "passCell")
    tableView!.registerNib(loginCell, forCellReuseIdentifier: "loginCell")
    keyboardHidden = true

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidShow:", name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardDidHide:", name: UIKeyboardWillHideNotification, object: nil)
}
文本字段应开始编辑:

func textFieldShouldBeginEditing(textField: UITextField!) -> Bool {
    let mailField = self.tableView.viewWithTag(1) as UITextField
    let passField = self.tableView.viewWithTag(2) as UITextField


    if textField == mailField {
        dispatch_async(dispatch_get_main_queue(), {
        let mailCell = textField.superview?.superview as mailTableCell
        UIView.transitionWithView(mailCell.icon, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromRight, animations: {
            mailCell.icon.highlighted = true
            }, completion: nil)
        })
    }
    if textField == passField {
        dispatch_async(dispatch_get_main_queue(), {
        let passCell = textField.superview?.superview as passwordTableCell
        UIView.transitionWithView(passCell.icon, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromRight, animations: {
            passCell.icon.highlighted = true
            }, completion: nil)
        })
    }
   return true
}
dequeueReusableCellWithIdentifier保证,如果已使用该标识符注册nib,则返回单元格。您不需要手动执行在退出队列后命名的LoadNibName。您正在将一个单元格出列,为其分配一个var,然后手动创建一个新单元格并覆盖出列的单元格。这就是为什么你不重复使用细胞

另一方面,您的类mailTableCell、passwordTableCell。。。应该大写,因为它们是类,而不是对象