【问题标题】:UITableView detailTextLabel not working with custom cellUITableView detailTextLabel 不适用于自定义单元格
【发布时间】:2012-05-16 11:14:05
【问题描述】:

我创建了一个自定义单元格,该单元格当前显示图像和文本,但不显示详细文本。

即使使用“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 个代表的图像):

【问题讨论】:

    标签: xcode ios5 uitableview custom-cell detailtextlabel


    【解决方案1】:
        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 中工作。

    【讨论】:

    • 感谢回复,我刚试了下,还是没有创建detailTextLabel。 textLabel 在单元格的中间居中,看起来好像没有字幕文本的空间 - 检查我添加的屏幕截图
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      尝试更改此行。

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

      我会用默认样式初始化。看看有没有帮助。

      【讨论】:

      • 感谢回复,可惜没有加字幕。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      相关资源
      最近更新 更多