Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView即使正确调用cellForRowAtIndexPath,也会显示空白单元格_Ios_Iphone_Objective C_Uitableview - Fatal编程技术网

Ios UITableView即使正确调用cellForRowAtIndexPath,也会显示空白单元格

Ios UITableView即使正确调用cellForRowAtIndexPath,也会显示空白单元格,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我有一个非常奇怪的问题,我感觉这将是一个奇怪的解决方案,就像我有一个错误的配置文件(检查了!) 我可以在模拟器和我的一部iPhone 5上运行,我有一个UITableView,里面有一些手机,一切都很好 然而,我刚刚在我的5S上运行了它,表视图完全是空白的。这些单元格是不可选择的。我已经检查了TableView没有被释放或其他任何东西,如果我下拉刷新它是有响应的。我甚至可以看到我的日志显示了行数。。。还有cellForRow。。如果我拉刷新,就会再次调用方法,只是根本没有显示UI 以下是各种代码

我有一个非常奇怪的问题,我感觉这将是一个奇怪的解决方案,就像我有一个错误的配置文件(检查了!)

我可以在模拟器和我的一部iPhone 5上运行,我有一个UITableView,里面有一些手机,一切都很好

然而,我刚刚在我的5S上运行了它,表视图完全是空白的。这些单元格是不可选择的。我已经检查了TableView没有被释放或其他任何东西,如果我下拉刷新它是有响应的。我甚至可以看到我的日志显示了行数。。。还有cellForRow。。如果我拉刷新,就会再次调用方法,只是根本没有显示UI

以下是各种代码片段,以备不时之需:

- (void)viewDidLoad
{
...
    UINib *cellNib = [UINib nibWithNibName:@"EJCMatchInboxCell" bundle:nil];
    [self.matchTable registerNib:cellNib forCellReuseIdentifier:kEJCMatchInboxCellIdent];

    UINib *segmentedCellNib = [UINib nibWithNibName:@"EJCSegmentedControlCell" bundle:nil];
    [self.matchTable registerNib:segmentedCellNib forCellReuseIdentifier:kEJCMatchInboxSegmentedControlCellIdent];
...
    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(refresh)
         forControlEvents:UIControlEventValueChanged];
    [self.matchTable addSubview:self.refreshControl];
...
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0 && indexPath.section == 0) {
        return NO;
    }

    return YES;
}

- (long)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (long)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    long rowCount = matches.count + 1;
    NSLog(@"MatchInboxVC::numberOfRowsInSection %li", rowCount);
    return rowCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"MatchInboxVC::cellForRowAtIndexPath %li", indexPath.row);

    if(indexPath.row == 0 && indexPath.section == 0) {
        // segmented control cell
        EJCSegmentedControlCell *cell = [tableView dequeueReusableCellWithIdentifier:kEJCMatchInboxSegmentedControlCellIdent];

        // Configure the cell...
        if (cell == nil) {
            cell = [[EJCSegmentedControlCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kEJCMatchInboxSegmentedControlCellIdent];
        }

        [cell.segmentedControl setSelectedSegmentIndex:selectedSegmentIndex];
        [cell.segmentedControl addTarget:self action:@selector(changedSegmentSelection:) forControlEvents:UIControlEventValueChanged];
        [cell.segmentedControl setTitle:@"Current" forSegmentAtIndex:0];
        [cell.segmentedControl setTitle:@"Deleted" forSegmentAtIndex:1];

        return cell;
    }
    else {
        // match cell
        EJCMatchInboxCell *cell = [tableView dequeueReusableCellWithIdentifier:kEJCMatchInboxCellIdent];

        // Configure the cell...
        if (cell == nil) {
            cell = [[EJCMatchInboxCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kEJCMatchInboxCellIdent];
        }

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        EJCMatch *m = matches[indexPath.row - 1];
        [cell setupWithMatch:m];

        return cell;
    }
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0 && indexPath.section == 0) {
        return 38.0f;
    }
    else {
        return 65.0f;
    }
}
记录输出:

MatchInboxVC::numberOfRowsInSection 2
MatchInboxVC::cellForRowAtIndexPath 0
MatchInboxVC::cellForRowAtIndexPath 1

对-我想这是我自己的错,因为我忘了正确读取方法定义,但显然在5S上为heightforrowatinexpath设置返回类型(float)将阻止单元格显示

通过将方法定义从

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath


我刚刚注意到应用程序中的每个表视图都出现了这种情况-所有表视图都在iPhone 5上工作,在模拟器中,没有一个在5S上工作???我还对模拟器进行了完全重置,以检查它没有缓存单元格或其他东西的XIB文件-并且它在模拟器上仍然可以完美地工作。从5S中删除应用程序并重新运行,但仍然无法运行。当您注册NIB时,我认为您不需要
if(cell==nil)
签入cellforrowatinexpath。你一定有一个牢房。因此,请尝试删除IF语句,包括其中的内容。有趣的是-我认为dequeueReusableCellWithIdentifier将返回nil,除非回收队列中有一个实际可用的单元格?我认为这个答案很好地解释了这一点:非常奇怪,在运行iOS7的两个设备上的行为是不同的。刚刚检查过,坏掉的设备运行的是7.0.4,而它正在使用的设备运行的是7.0,所以他们肯定在这些版本之间引入了一些东西。。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath