2010-10-28 11 views

Respuesta

6

Si no necesita que se pueda editar, simplemente configure la propiedad enabled de su vista de texto como NO.

+4

userInteractionEnabled = NO trabajado. Muchas gracias. –

+0

Un textView no tiene una propiedad habilitada. –

3

Puede asignar un delegado a su UITextView, y en su método textViewShouldBeginEditing: puede llamar manualmente al método didSelectRowAtIndexPath. Si no puede obtener fácilmente el indexPath de la fila para seleccionar, puede usar una subclase de UITextView que tenga una propiedad indexPath, y en el método cellForRowAtIndexPath: cuando cree su UITextView, establezca la propiedad indexPath.

+0

También puede llamar a selectRowAtIndexPath: animated: scrollPosition aquí para obtener la animación de resaltado en la celda de la tabla si desea ese comportamiento. – Rudism

5

Para UITextView conjunto textView.userInteractionEnabled = false y si tiene UITextField, establezca textField.userInteractionEnabled = false.

Si desea que el Textview o textField a ser editable después de la celda con que se toca, hace algo como esto:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    tableView.deselectRowAtIndexPath(indexPath, animated: true) 

    let cell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell 

    // find first textField inside this cell and select it 
    for case let textField as UITextField in cell.subviews { 
    textField.userInteractionEnabled = true 
    textField.becomeFirstResponder() 
    return 
    } 

    // find first textView inside this cell and select it 
    for case let textView as UITextView in cell.subviews { 
    textView.userInteractionEnabled = true 
    textView.becomeFirstResponder() 
    return 
    } 
} 

A continuación, asegúrese de desactivar la interacción del usuario después de haber terminado la edición:

func textFieldDidEndEditing(textField: UITextField) { 
    textField.userInteractionEnabled = false 
    // rest of the function 
    } 

    func textViewDidEndEditing(textView: UITextView) { 
    textView.userInteractionEnabled = false 
    // rest of the function 
    } 

no se olvide de establecer el UITextFieldDelegate y/o UITextViewDelegate

espero que esto ayudó a alguien :)

+1

He estado estableciendo la propiedad 'editable' de' UITextView' en 'NO', lo cual no funcionó. Configurar 'userInteractionEnabled' a' NO' funcionó. –

Cuestiones relacionadas