2010-10-28 19 views

risposta

6

Se non è necessario modificarlo, impostare la proprietà enabled della vista del testo su NO.

+4

userInteractionEnabled = NO lavorato. Grazie mille. –

+0

Una vista testo non ha una proprietà abilitata. –

3

È possibile assegnare un delegato a UITextView e, nel suo metodo textViewShouldBeginEditing:, è possibile chiamare manualmente il metodo didSelectRowAtIndexPath. Se non è possibile ottenere facilmente indexPath della riga da selezionare, è possibile utilizzare una sottoclasse di UITextView con una proprietà indexPath e in cellForRowAtIndexPath: method, quando si crea UITextView, impostare la proprietà indexPath.

+0

È inoltre possibile chiamare selectRowAtIndexPath: animated: scrollPosition qui per ottenere l'animazione di evidenziazione sulla cella della tabella, se si desidera tale comportamento. – Rudism

5

Per UITextView impostare textView.userInteractionEnabled = false e se si dispone di UITextField, impostare textField.userInteractionEnabled = false.

Se si desidera che il textView o textField di essere modificabile dopo la cella con esso è sfruttato, fare qualcosa di simile:

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 
    } 
} 

quindi assicurarsi di disattivare l'interazione utente dopo aver terminato l'editing:

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

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

non dimenticare di impostare il UITextFieldDelegate e/o UITextViewDelegate

Spero che questo ha aiutato qualcuno :)

+1

Ho impostato la proprietà 'editable' di' UITextView' su 'NO', che non ha funzionato. Impostando 'userInteractionEnabled' su' NO' ha funzionato. –

Problemi correlati