In Objective C per ottenere UILabel in UIViewController per tag.
qui prendo assunto come UILabel
è aggiunto il self.view
, altrimenti è possibile passare la visualizzazione in cui si è aggiunto UILabel
come [yourview viewWithTag:1];
UILabel *label = (UILabel *)[self.view viewWithTag:1];
In UITableView
UILabel *label = (UILabel *)[cell viewWithTag:1];
cellulare è un oggetto di UITableViewCell
as
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
In Swift 3
let label:UILabel = self.view.viewWithTag(1) as! UILabel
In UITableView
let cell:UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell") as UITableViewCell!
let label:UILabel = cell.viewWithTag(1) as! UILabel
NOTA: prima di usare tag (viewWithTag) ci dovrebbe essere oggetto (UILabel) con quel numero di targa, altrimenti app è incidente .
è possibile impostare tag per qualsiasi oggetto tramite storyboard o tramite XIB e programmaticamente.
fonte
2017-06-30 09:35:48
Come hai impostato il tag ed è l'etichetta l'unica vista che è la sottoview (o più in basso nell'albero) di 'self' con il tag' 1'? –
Ho impostato il tag come [label setTag: 1]; in un'altra funzione. L'etichetta non si trova nella sottoview in alto ma è nella vista superiore –
È necessario enumerare 'self subviews' per ottenere l'etichetta desiderata. Il tuo tentativo non funzionerà. –