0

I've created a custom cell which currently is showing an image and text, but not the detail text.

Even with "cell.detailTextLabel.text", it still won't show. Would anybody have an idea what's wrong?

I've tried changing UITableViewCellStyleSubtitle to UITableViewCellStyleDefault and others.

I've searched this site and google for the last couple of hours trying fixes, none of them worked.

Any help would be appreciated.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"myCell";
    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    }

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES selector:@selector(localizedCompare:)];
NSArray *sortedCategories = [self.tweetSongs.allKeys sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];

NSString *categoryName = [sortedCategories objectAtIndex:indexPath.section];

NSArray *currentCategory = [self.tweetSongs objectForKey:categoryName];

NSDictionary *currentArtist = [currentCategory objectAtIndex:indexPath.row];
NSDictionary *currentSong = [currentCategory objectAtIndex:indexPath.row];

cell.textLabel.text = [currentSong objectForKey:@"Song"];
cell.detailTextLabel.text = [currentArtist objectForKey:@"Artist"];
cell.textLabel.textColor = [UIColor whiteColor];
cell.imageView.image = [UIImage imageNamed:[currentArtist objectForKey:@"Artwork"]]
}

Here's a link to the screenshot of the cells (i'm not allowed to attach an image without a rep of 10):

enter image description here

Guru
  • 21,652
  • 10
  • 63
  • 102
mhorgan
  • 886
  • 2
  • 11
  • 32

3 Answers3

0
    cell.textLabel.text = [currentSong objectForKey:@"Song"];
    cell.detailTextLabel.text = @"YourName"; //[currentArtist objectForKey:@"Artist"];
    cell.detailTextLabel.textColor = [UIColor redColor];
    cell.textLabel.textColor = [UIColor blackColor];//Change your color
    cell.imageView.image = [UIImage imageNamed:[currentArtist objectForKey:@"Artwork"]];

Try like this. It is worked in my Xcode.

Prasad G
  • 6,702
  • 7
  • 42
  • 65
  • Thanks for the reply, I just tried it and it still doesn't create a detailTextLabel. the textLabel is centered in the middle of the cell, it looks as if there's no room for the subtitled text - check the screenshot i added – mhorgan May 16 '12 at 13:02
0

Try changing this line.

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

I would init with style default instead. See if that helps.

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
0

The problem was that the custom cell's height was too small, i think anyway because it worked when I increased the height.

mhorgan
  • 886
  • 2
  • 11
  • 32