Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 设置自定义UITableViewCell的问题_Ios_Uitableview - Fatal编程技术网

Ios 设置自定义UITableViewCell的问题

Ios 设置自定义UITableViewCell的问题,ios,uitableview,Ios,Uitableview,我已经使用NIB中的自定义UITableViewCell创建了一个UITableView。加载视图控制器时,一切似乎都正常工作。但是,当我开始滚动 UITable VIEW/CODE >时,有一个空单元格出现在中间,根本没有理由。 我不知道发生了什么事。我的cellforrowatinexpath非常简单。但是我已经在自定义的UITableViewCell中添加了手势。这会引起问题吗? 这是我的代码: - (UITableViewCell *)tableView:(UITableView *)t

我已经使用NIB中的自定义
UITableViewCell
创建了一个
UITableView
。加载视图控制器时,一切似乎都正常工作。但是,当我开始滚动<代码> UITable VIEW/CODE >时,有一个空单元格出现在中间,根本没有理由。

我不知道发生了什么事。我的
cellforrowatinexpath
非常简单。但是我已经在自定义的
UITableViewCell
中添加了手势。这会引起问题吗? 这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tableIdentifier = @"FTStreamCell";
    FTStreamCell *cell = (FTStreamCell *)[tableView dequeueReusableCellWithIdentifier:tableIdentifier];
        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FTStreamCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.delegate = self;
        return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    FTStreamCell *streamCell = (FTStreamCell*) cell;
    if (!indexPath.section == 0)
    {
        if ((NSNull*)[[[self.cachedData objectForKey:kQuestions] objectAtIndex:indexPath.row] objectForKey:kQuestion] != [NSNull null])
            streamCell.question.text = [[[self.cachedData objectForKey:kQuestions] objectAtIndex:indexPath.row] objectForKey:kQuestion];
        streamCell.timePosted.text = [NSString stringWithFormat:@"Today at Bangalore, India"];
        // To Show My Questions
        NSLog(@"Me %d", [[[NSUserDefaults standardUserDefaults] objectForKey:kUserId] integerValue]);
        if ([[[self.cachedData objectForKey:kQuestions] objectAtIndex:indexPath.row] objectForKey:kUserId] == [[NSUserDefaults standardUserDefaults] objectForKey:kUserId])
        {
            streamCell.mainView.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:240.0f/255.0f blue:247.0f/255.0f alpha:1];
            streamCell.userCheck = YES;
        }
        else
        {
            streamCell.mainView.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1];
            streamCell.userCheck = NO;
        }
        [cell layoutSubviews];
    }
}

谢谢。

UITableView重用表格单元格以减少内存分配。因此,当您开始滚动时,“白色单元格”很可能是以前使用和修改过的单元格。在willDisplayCell方法中,尝试在应用样式更改之前“重置”单元格。“重置”将是您的自定义方法,它可以将单元格内的所有内容更改回默认值。

在Xcode中启用NSZombie,以便您知道其崩溃的位置。它不会给我任何崩溃。但是空白的细胞仍然在那里。我没有足够的声誉来发布截图。这是它的链接。设置断点以检查何时加载空白单元格。它是空白的,是因为你在
else
部分使用白色吗?我认为它会崩溃,因为你试图访问任何空对象,这就是为什么单元格是空白的。尝试在启用NSZombie模式后崩溃应用程序,而不是在这里发布屏幕截图,在这里你会崩溃。我没有在任何地方将其设置为白色。我想弄清楚这件事已经有一段时间了。因为我不知道它确切发生的时间,所以使用断点是一件非常困难的事情。滚动时在随机单元格上不断发生。我该怎么做?将其分配给nil或其他有帮助的方法吗?您可以在cellForRowAtIndexPath方法中将其分配给nil,以强制问题是。是否曾经有过这样的情况:第节顺便说一下,0?我有一个带有clearColor的部分,用于显示tableView后面的图像。其余部分在第1节。类似于路径的东西。