如何在UITableView中引入一个以编程方式生成的UILabel

Dou*_*ull -1 iphone objective-c uitableview ios

我有一个编程生成的UITableView,有许多UIlabel.应该在前面看到每个添加的UILabel.一切正常,直到我添加最终的UILabel,它出现在所有其他的后面.

我怎么能把它带到前面?

- (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
        }
Run Code Online (Sandbox Code Playgroud)

...

其他UILABELS在这里添加.

而且,这里是最终的UILABEL,它出现在休息之后,当它应该出现在前面时:

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 ];
Run Code Online (Sandbox Code Playgroud)

A's*_*ens 6

[cell bringSubviewToFront:label];
Run Code Online (Sandbox Code Playgroud)