2010-09-07 7 views

Odpowiedz

87

Użyj metody viewWithTag. na przykład jeśli przycisk jest w widoku kontrolera i tag twój guzik jest 100 dodaje się linia powróci przycisk:

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

EDIT:

Wirtualny widok z konkretnego tagu w Swift -

let view = self.view.viewWithTag(100) 

Jeśli chcesz się upewnić, że masz określony typ widoku, powiedzmy UIButton, powinieneś sprawdzić typ:

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

// Teraz można dostać swoją przycisk na podstawie wartości znacznika

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); 
Powiązane problemy