2012-05-16 99 views
0

我已经创建了一个自定义单元格,它目前正在显示图像和文本,但不是详细信息文本。UITableView detailTextLabel不能与自定义单元格一起工作

即使使用“cell.detailTextLabel.text”,它仍然不会显示。有人会有什么想法吗?

我试着将UITableViewCellStyleSubtitle改为UITableViewCellStyleDefault和其他。

我已经搜索了这个网站和谷歌最近几个小时尝试修复,他们都没有工作。

任何帮助,将不胜感激。

-(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"]] 
} 

下面是细胞的截图链接(我不能附加图像无10 REP):

enter image description here

回答

0

问题在于自定义单元格的高度太小,我认为无论如何因为它在我增加高度时起作用。

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"]]; 

尝试这样的。它在我的Xcode中工作。

+0

感谢您的回复,我只是试了一下,它仍然没有创建一个detailTextLabel。 textLabel居中在单元格中间,看起来好像没有空间显示字幕文本 - 查看我添加的截图 – mhorgan

0

尝试更改此行。

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

我会初始化样式默认代替。看看是否有帮助。

+0

感谢您的回复,但很遗憾,它没有添加小标题。 – mhorgan

相关问题