2010-09-07 5 views

Respuesta

87

Utilice el método viewWithTag. p.ej. Si el botón está a la vista de su controlador y la etiqueta de su botón es 100 la siguiente línea devolverá el botón:

UIButton *button = (UIButton *)[self.view viewWithTag:100]; 

EDIT:

Obtener vista con etiqueta en particular en Swift -

let view = self.view.viewWithTag(100) 

Si desea asegurarse de tener el tipo específico de vista, digamos un UIButton, debe verificar el tipo:

if let button = self.view.viewWithTag(100) as? UIButton { 
    //Your code 
} 
5
UIButton *button=(UIButton *)[self.view viewWithTag:tag]; 

// Ahora usted puede conseguir su botón basado en el valor de etiqueta

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); 
Cuestiones relacionadas