Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is detailTextLabel not visible?

detailTextLabel is not visible (code below). Can you tell me why?

 // Customize the appearance of table view cells.
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

NSString *cellValue = [myListArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

cell.detailTextLabel.text = @"Hello "; // This is not visible
cell.image = [myListArrayImages objectAtIndex:indexPath.row];

return cell;
}
like image 380
Chatar Veer Suthar Avatar asked Mar 04 '11 06:03

Chatar Veer Suthar


5 Answers

The detailTextLabel is not displayed for cells with the UITableViewCellStyleDefault style. init the UITableViewCell with UITableViewCellStyleSubtitle instead and you should see your detailTextLabel.

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
like image 149
Opsimath Avatar answered Oct 17 '22 20:10

Opsimath


Or if you are using Interface Builder, change the Style cell property to Subtitle. :)

Style cell property in Interface Builder.

like image 38
reinaldoluckman Avatar answered Oct 17 '22 20:10

reinaldoluckman


In order to solve it programmatically:

let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "identifier")
like image 35
Lukas Mohs Avatar answered Oct 17 '22 20:10

Lukas Mohs


I have used this and it worked for me:

// programming mark ----- ----- ---- ----- ----- ---- ----- ----- ----

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let CellIdentifier: String = "CellIdentifier"

    var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: CellIdentifier)
    }

    cell!.textLabel!.text = "Title"
    cell!.detailTextLabel!.text = "Value"

    return cell!
}
like image 33
Vinod Joshi Avatar answered Oct 17 '22 22:10

Vinod Joshi


Swift 5

You can enable this inside cellForRowAt method

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")

    cell.textLabel?.text = qus[indexPath.row]
    cell.detailTextLabel?.text = ans[indexPath.row]
    return cell
}
like image 1
Umer Khan Avatar answered Oct 17 '22 21:10

Umer Khan