2010-09-07 17 views

Trả lời

87

Sử dụng phương thức viewWithTag. ví dụ. nếu nút bấm của bạn là theo quan điểm của bộ điều khiển của bạn và tag của nút của bạn là 100 dòng sau sẽ trở lại vào nút:

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

EDIT: Xem

Nhận với thẻ đặc biệt trong Swift -

let view = self.view.viewWithTag(100) 

Nếu bạn muốn đảm bảo rằng bạn có loại chế độ xem cụ thể, hãy nói UIButton, bạn nên kiểm tra loại:

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

// Bây giờ bạn có thể nhận nút của bạn dựa trên giá trị thẻ

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); 
Các vấn đề liên quan