Search code examples
iosuitableviewparametersuilabelcustom-cell

How can I change custom cells label parameters in viewDidLoad?


I have custom cell called MyCustomCell, there is a label named pushLabel, in table view I get parameters of label like this:

cell.pushLabel.text = @"text";

I need to get in that label parameters in viewDidLoad (where table view is located), how this can be done?


Solution

  • In viewDidLoad method, UITableView still should have not been loaded so there no way you can get UITableViewCell objects.

    One solution can be, maintain flag say you have

    //Add in your .h file
    BOOL hidePushLabel;
    

    Now use these flag to hide intially in tableview like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
       NSString *strCellIndentifier = @"cell";
       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIndentifier];
    
       if (cell)
       {
           //By default hidePushLabel will be NO so hide pushLabel
           if(!hidePushLabel)
              cell.pushLabel.hidden = YES;
           else
              cell.pushLabel.hidden = NO;
       }
       return cell;
    }