Saturday, 28 September 2013

how to bring to front a programatically generated UILabel in a UITableView

how to bring to front a programatically generated UILabel in a UITableView

I have a programatically generated UITableView with many UIlabel's. Each
added UILabel should be seen in front. All works ok until I add the final
UILabel, which appears behind all the others.
How can I bring it to the front?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
... if (cell == nil) { if( dbg ) NSLog( @" - cell nil"); cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier]; /* Though it's
UITableViewCellStyleDefault, the three defaults (image, label, detail
label) are nil if not set. */
// UI controls must be preset for re-used, to prevent memory
leak:
// Allocate max. possible UI controls for this row, once per
boot:
int instance;
for( instance=0; instance < MAX_CELL_UILABEL; ++instance )
{
UILabel* cell_UILabel = [[UILabel alloc]
initWithFrame: CGRectZero]; // allocate next UI
control
[cell.contentView addSubview: cell_UILabel ];
// add it permanently to the cell
cell_UILabel.tag = BASE_UILABEL_TAG + instance;
// assign unique ID for later lookup
}
...
OTHER UILABELS ARE ADDED HERE.
AND, HERE IS THE FINAL UILABEL, WHICH APPEARS BEHIND THE REST, WHEN IT
SHOULD APPEAR IN FRONT:
UILabel* battery_percent =
(UILabel*)[cell.contentView viewWithTag:
BASE_UILABEL_TAG + ul++];
battery_percent.frame = CGRectMake (x,y, w,h);
battery_percent.backgroundColor = [UIColor
orangeColor];
battery_percent.textAlignment =
NSTextAlignmentCenter; // NSTextAlignmentRight,
NSTextAlignmentLeft
battery_percent.font = [UIFont systemFontOfSize:
font_size];
battery_percent.textColor=[UIColor whiteColor];
battery_percent.numberOfLines=0;
// Show battery %:
battery_percent.text = [NSString
stringWithFormat: @"%d%%",
battery_charge_percent ];

No comments:

Post a Comment