0
-viewDidLoad {
    tbl.rowHeight = 150;
    ary = [[NSArray alloc]initWithObjects:@"asdf",@"asd",nil];
    ary2 = [[NSArray alloc]initWithObjects:@"google",@"yahoo",nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [ary count];
}

// 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.
    cell.textLabel.text = [ary objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [ary2 objectAtIndex:indexPath.row] ;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
         return cell;
}

The problem for me is detailtextlabel not displaying in table view. Are there any errors in my code?

Halle
  • 3,584
  • 1
  • 37
  • 53
Nipin P N
  • 127
  • 2
  • 8

6 Answers6

2

you have to set cell styleSubtitle as subtitle like below

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
Kundan
  • 3,084
  • 2
  • 28
  • 65
dks1725
  • 1,631
  • 1
  • 20
  • 29
1

Change the uitableviestyltDEfault to uitableviewStyleSubtitle

Kasaname
  • 1,491
  • 11
  • 15
1

Make sure you're using an UITableViewCellStyle anything but not UITableViewCellStyleDefault should this work, please see this for more details:

cell.detailTextLabel.text not working... why

Community
  • 1
  • 1
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
0

Anything but UITableViewCellStyleDefault should work with a detailLabel.

Joetjah
  • 6,292
  • 8
  • 55
  • 90
0

Add detailtextLabel on the cell's contentView.

Vin
  • 10,517
  • 10
  • 58
  • 71
0

See the below link

In UITableView, cell.detailTextLabel.text isn't working… why?

Community
  • 1
  • 1
vinay
  • 1,276
  • 3
  • 20
  • 34