UITableView单元格文本标签不显示文本

时间:2013-08-02 20:01:12

标签: ios uitableview

我在表格视图单元格中创建了一个标签,但是我想在标签中显示的文字没有显示下面是我的代码。标签正在正确创建,但文本未显示我想从数组中显示的内容。

 UILabel *mylabel = [[UILabel alloc] initWithFrame:CGRectMake(35,13, 230, 30)];

[cell.contentView addSubview:mylabel];
mylabel.text = [array1 objectAtIndex:row];

3 个答案:

答案 0 :(得分:1)

取出所有代码并放置:

 cell.textLabel.text = [array1 objectAtIndex:row];

编辑尝试:

cell.accessoryView = mylabel;

答案 1 :(得分:0)

我刚刚使用Xcode 5 DP4(iOS 7项目)创建了一个新项目。我在故事板中放置了一个带有一个原型单元的表视图控制器。然后在表委托中,我添加了您的代码。看起来像这样

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        UILabel *mylabel = [[UILabel alloc] initWithFrame:CGRectMake(35,13, 230, 30)];
        [cell.contentView addSubview:mylabel];
        mylabel.text = @"Hello";
        return cell;
    }

这是按预期工作的。您是否尝试过像我刚才那样在新项目中隔离代码?也许问题与您粘贴的实际代码无关。

答案 2 :(得分:0)

请参阅UILabel in UITable do not get display but get display on click in IOS 7 (due to issue with background colour)

问题仅仅是因为细胞背景颜色和文字颜色相同。 希望对你有帮助。

相关问题