Voglio tornare indietro, ho già assegnato il tag lì, come posso farlo? Grazie.Posso ottenere l'elemento tramite Tag da iPhone SDK?
32
A
risposta
87
Utilizzare il metodo viewWithTag
. per esempio. se il pulsante è in vista del vostro controller e tag del pulsante è di 100 la seguente riga restituirà il tasto:
UIButton *button = (UIButton *)[self.view viewWithTag:100];
EDIT: vista
ottenere con particolare tag a Swift -
let view = self.view.viewWithTag(100)
Se vuoi assicurarti di avere il tipo di visualizzazione specifico, ad esempio un UIButton, dovresti controllare il tipo:
if let button = self.view.viewWithTag(100) as? UIButton {
//Your code
}
5
UIButton *button=(UIButton *)[self.view viewWithTag:tag];
// Ora è possibile ottenere il pulsante sulla base del valore di tag
0
//Get View using tag
UITextField *textFieldInView = (UITextField*)[self.view viewWithTag:sender.tag+1000];
UILabel *labelInView = (UILabel*)[self.view viewWithTag:sender.tag+2000];
//Print its content based on the tags
NSLog(@"The tag is %d ", textFieldInView.tag);
NSLog(@"The tag is %d ", labelInView.tag);
NSLog(@"The Content is %@ ", textFieldInView.text);
NSLog(@"The Content is %@ ", labelInView.text);