ios - 默认实现中缺少 UITableViewCell detailTextLabel

标签 ios objective-c uitableview

对大家来说这似乎是一个重复的问题,但我已阅读所有主题,但尚未找到答案,因此我决定发布一个新问题。

我正在使用 UITableViewCellStyleSubtitle 的默认实现,但 detailTextLabel 不会出现,除非我每次都创建一个新单元格。

这是代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [tblvUsersList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return (self.registeredUser && self.registeredUser.count > 0)?self.registeredUser.count:0;
}

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

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    if (self.registeredUser.count > indexPath.row) {

        AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];

        if (self.currentViewType == ViewTypeUsers) {
            UserModal* user = [self.registeredUser objectAtIndex:indexPath.row];
            cell.textLabel.text = user.userName;
            cell.detailTextLabel.text = user.email;
           // NSLog(@"Detail Text is %@",cell.detailTextLabel.text);
          //Console Prints Null here            
    }

    return cell;
}

最佳答案

尝试换行

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

关于ios - 默认实现中缺少 UITableViewCell detailTextLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24904355/

相关文章:

objective-c - PresentPopoverFromBarButtonItem

ios - 我应该使用什么,UITableView 或 UICollectionView?

ios - 为什么当我更改边界时 View 没有变化?

iphone - 如何只选择一部分 UIView 转换为 UIImage

ios - 无法从 JSON 数据集中获取位置坐标

ios - 在 iPhone 的 safari 中通过应用程序打开谷歌地图

ios - HTTP(S) POST : connectionDidFinishLoading gets called with empty data, 可能存在信任问题

ios - didUpdatePushCredentials 没有被调用

iOS 表格标题和单元格之间的快速边距

ios - UITableView 底部不需要的黑色单元格