K Hsueh
K Hsueh

Reputation: 620

cell.detailTextLabel not working

I want to set up a textLabel and a detailTextLabel for my table. The textLabel is working properly. However, I couldnt get the detailTextLabel to display the text that I have set. Below is my code

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = @"SomeString";
    cell.detailTextLabel.text = @"hello";

    return cell;
}

Upvotes: 0

Views: 751

Answers (3)

EditOR
EditOR

Reputation: 367

I have faced similar issue as like @user1829700.

My initial settings are

TableView --> Prototype Cell --> (Attribute Inspector) Style - set to Custom (by design)

Changed Style to - Subtitle, it does the trick

Upvotes: 1

David Douglas
David Douglas

Reputation: 10503

In your custom table cell implementation try adding @synthesize detailTextLabel;

Header (.h):

@property (nonatomic, weak) IBOutlet UILabel *textLabel;
@property (nonatomic, weak) IBOutlet UILabel *detailTextLabel;

Implementation (.m):

@synthesize textLabel;
@synthesize detailTextLabel;

Upvotes: 0

iAppDeveloper
iAppDeveloper

Reputation: 1088

Try this Use appropriate UITableViewCellStyle with this (anything but UITableViewCellStyleDefault should thus work). The cell's style is specified when you initialize it.

Upvotes: 0

Related Questions