2010-09-07 94 views

回答

87

使用viewWithTag方法。例如如果你的按鈕是在控制器的觀點和你的按鈕的標籤是100下面一行將返回按鈕:

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

編輯:與特定標籤

獲取視圖斯威夫特 -

let view = self.view.viewWithTag(100) 

如果你想確保你有特定類型的視圖,比如UIButton,你應該檢查類型:

if let button = self.view.viewWithTag(100) as? UIButton { 
    //Your code 
} 
5
UIButton *button=(UIButton *)[self.view viewWithTag: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); 
相關問題