I am learning how to handle subviews and I am having difficultly manipulating the position of one of them. Each subview has a unique tag. It is worth noting that I am searching for subviews in a UITableCell, the UITableView has about 5 rows.
If I do either this:
UIView *mike = [self.view viewWithTag:6];
mike.frame = CGRectMake(250, 5, 25, 20);
mike.backgroundColor = [UIColor redColor];
NSLog(@"mike=%@ tag=%d",[[mike class] description], [mike tag]);
or:
UILabel *label = (UILabel *)[self.view viewWithTag:6];
label.frame = CGRectMake(250, 5, 25, 20);
label.backgroundColor = [UIColor redColor];
NSLog(@"label=%@ tag=%d",[label text], [label tag]);
the subview does not change position, however if I search for it using the code below it does work.
for (UIView *subview0 in [self.view subviews])
{
for (UIView *subview1 in [subview0 subviews])
{
for (UIView *subview2 in [subview1 subviews])
{
if ([[[subview2 class] description] isEqualToString: @"UILabel"])
{
[subview2 setText:@"mike"];
subview2.frame = CGRectMake(250, 5, 25, 20);
subview2.backgroundColor = [UIColor redColor];
}
}
}
}
Any help greatly appreciated.
Mike
EDIT: from console on execution
2011-03-10 19:53:42.344 mike=UILabel tag=6 0x4b59610
2011-03-10 19:53:42.344 label=842 tag=6 0x4b59610
2011-03-10 19:53:42.345 0-subview=PerformAnalysisCustomCell tag=0
2011-03-10 19:53:42.345 1-subview=UIGroupTableViewCellBackground tag=0
2011-03-10 19:53:42.346 2-subview=UIView tag=0 0x4d62910
2011-03-10 19:53:42.349 1-subview=UITableViewCellContentView tag=0
2011-03-10 19:53:42.349 2-subview=UILabel tag=0 0x4b51320
2011-03-10 19:53:42.350 2-subview=UILabel tag=1 0x4b59290
2011-03-10 19:53:42.350 2-subview=UILabel tag=2 0x4b59370
2011-03-10 19:53:42.358 2-subview=UILabel tag=3 0x4b59410
2011-03-10 19:53:42.359 2-subview=UILabel tag=4 0x4b594b0
2011-03-10 19:53:42.360 2-subview=UILabel tag=5 0x4b59560
2011-03-10 19:53:42.360 2-subview=UILabel tag=6 0x4b59610
After putting the %p in the NSLog you can the memory address address is the same. Other tag=6 lines have different addresses so I should expect at least that cell to move.
You need to run your viewWithTag statement on each cell, not on the entire tableView. This should most likely be set in cellForRowAtIndexPath, and then you would reload the rows that changed when you need to.