I've created a UITableView
with a custom UITableViewCell
from a NIB. On loading the view controller, everything seems to work fine. But when I start to scroll the UITableView
, there are cases where an empty cell appears in the middle for no reason atall.
I dont know what's happening. My cellForRowAtIndexPath
is quite straightforward. But I've added gestures to the custom UITableViewCell
. Could that be causing a problem?
Here my code:
- (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];
}
}
Thanks.