【问题标题】:UITableView Does not show data in ipad appUITableView 在 ipad 应用程序中不显示数据
【发布时间】:2013-08-28 09:47:27
【问题描述】:

我有 ipad 应用程序,我在其中使用 tableView 显示数据,但问题是它没有在 tableView 中显示数据这里是设置单元格值的代码

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                   reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    if (tableView == tableCategory) {

        cell.textLabel.font=[UIFont fontWithName:@"Arial" size:16];
        cell.textLabel.textAlignment=UITextAlignmentLeft;    

        ObjectData*theCellData = [categoryArray objectAtIndex:indexPath.row];
        cell.textLabel.text=theCellData.categoryTitle;

        return cell;
    }
    else if (tableView == tableSubCategory)
    {
        cell.textLabel.font=[UIFont fontWithName:@"Arial" size:16];
        cell.textLabel.textAlignment=UITextAlignmentLeft;    
        ObjectData*theCellData = [subCategoryArray objectAtIndex:indexPath.row];

        NSString *test = theCellData.subCategoryTitle;
        NSLog(@"Test Cell is %@",test);
        cell.textLabel.text = test;

        return cell;    
    }
    else if(tableView == tablePublish)
    {
        cell.textLabel.font = [UIFont fontWithName:@"Arial" size:16];
        cell.textLabel.textAlignment = UITextAlignmentLeft;    

        GetPublishData *theCellData = [publishArray objectAtIndex:indexPath.row];
        NSString *test = [NSString stringWithFormat:@"%@:%@:%@ in:%@:%@",theCellData.UserName,theCellData.ContentTitle,theCellData.ContentType,theCellData.Catgeory,theCellData.SubCategory];
        NSLog(@"Test Cell is %@",test);
        cell.textLabel.text = test;
        cell.detailTextLabel.text = theCellData.ContenAddedTime;

        return cell;
    }
    else
    {
        cell.textLabel.font = [UIFont fontWithName:@"Arial" size:16];
        cell.textLabel.textAlignment = UITextAlignmentLeft;  

        GetPublishData *theCellData = [publishArray objectAtIndex:indexPath.row];

        NSString *test = theCellData.ContentDescription;
        cell.textLabel.text = test;

        return cell;
    }
}

我有 tableView 委托和数据源,但在检查数组中的计数时仍然没有显示任何内容,它显示了其中的项目,但没有在 tableview 中显示数据 我为 else 表显示的数据不起作用

【问题讨论】:

  • 你能编辑你的问题并展示你的整个方法吗- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  • @zbMax 已编辑请查看代码
  • 曾经调用过表格视图方法吗?
  • 你写过 [yourTableview reloadData];
  • 是的,我写了 tableView reloadData

标签: ios ipad uitableview


【解决方案1】:

什么返回你的方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section?你能展示你的代码吗?

还要检查您是否为所有表设置了委托和数据源。

请原谅我发布这个类似的答案。我没有在 cmets 发帖的名声。

【讨论】:

  • 没关系,我已经为所有表设置了委托和数据源
  • 那么 numberOfRowsInSection 方法呢?你能检查一下吗?这个表应该有多少行?
  • 他们也完美地显示了数组计数,但它没有显示在单元格中
  • 还有一件事:您可以从其他表中删除数据源和委托,并将其留给有问题的表,然后您可以调试方法 cellForRowAtIndexPath:。我想通过这种方式你可以找到问题。
  • 能否加一行 NSLog(@"Test Cell is %@ for else case",test);到其他块?它是否显示在控制台中?还要检查方法 numberOfSectionsInTableView。
【解决方案2】:

检查单元格标识符..您是否为表格单元格提供了任何自定义单元格标识符?在这里,您将其称为

NSString *CellIdentifier = @"Cell";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多