Brian Reading wrote:
Using Objective-C, can someone post a code sample showing how one would programmatically assign an integer to the tag property of a control (let's say a label), and then spit out the text of the label into NSLog by calling its tag?
- (void)viewDidLoad {
[super viewDidLoad];
// create a column of 6 labels with tag nos. 100-105
CGRect frame = CGRectMake(20, 0, 120, 37);
for (int i=0, tag=100; i < 6; i++, tag++) {
frame.origin.y = frame.origin.y + 50;
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text = [NSString stringWithFormat:@"Label No. %d", i];
label.textAlignment = UITextAlignmentCenter;
label.tag = tag;
[self.view addSubview:label];
[label release];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// get the text for label 103
UILabel *label = (UILabel*)[self.view viewWithTag:103];
NSLog(@"Text for label 103: %@", label.text);
}
- Ray