Search code examples
iosobjective-cuitableviewuiswitch

UISwitch detailed text underneath


Text not underneath

I want to be able to put the descriptive text underneath the label. Below is the code I have thus far:

UISwitch *toggle = [[UISwitch alloc] init];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
    cell.textLabel.text = @"Remote Execution";
    cell.detailTextLabel.text = @"Remote execution will permit registered devices to execute tests without manually starting them";
    [cell addSubview:toggle];
    cell.accessoryView = toggle;
    [cell.detailTextLabel setAlpha:1.0];
    [cell.detailTextLabel setTextColor:[UIColor redColor]];

Solution

  • Use UITableViewCellStyleSubtitle instead of UITableViewCellStyleValue1:

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];