0

As soon as the table view gets touched the cell titles (and on-tap actions) disappear. I only use standard table view cells and store the values in an array. After the values disappear the table stays scrollable. Any ideas?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.textLabel.text = [[systeme objectAtIndex:indexPath.row] description];
    cell.backgroundColor = [UIColor clearColor];
    [cell.textLabel setTextColor:[UIColor whiteColor]];
    [cell.textLabel setTextAlignment:NSTextAlignmentCenter];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"choseSystem" object:[systeme objectAtIndex:indexPath.row]];
}
Johannes
  • 325
  • 4
  • 11
  • 5
    show us your `didSelectRowAtIndexPath` method – Pancho May 27 '14 at 15:13
  • 1
    Any reason you use a different reuse identifier for every row if you're using standard cells? – Stonz2 May 27 '14 at 15:13
  • 1
    @Stonz2, do you mean every section? `[NSString stringWithFormat:@"Cell_%ld", (long)indexPath.section];` – lucianomarisi May 27 '14 at 15:15
  • He has only one section, but yes it doesn't make sense – Pancho May 27 '14 at 15:15
  • 1
    Oops- good catch. Either way, seems silly if you're going to use default cells regardless. – Stonz2 May 27 '14 at 15:15
  • 1
    By "gets touched", do you mean a tap that selects a cell, or does this happen on scrolling as well? – rdelmar May 27 '14 at 15:24
  • @rdelmar It happens as soon as I touch the table view, no matter if I'm scrolling or actually trying to select a cell – Johannes May 27 '14 at 16:06
  • @PanayotPanayotov Breakpoints indicate that `didSelectRowAtIndexPath` doesn't get called, but I added it – Johannes May 27 '14 at 16:09
  • Is the background color of the table view (not the cell) something other than white? There's nothing in the code you posted that should cause the problem you're seeing unless having white text is the problem (but I don't know why the text would appear initially). – rdelmar May 27 '14 at 16:50

2 Answers2

0

You should be sure that the reuse identifier is the same for all cells if you use only one type of cells. You should do something similar to the following in the portion of your code where to retrieve a reusable cell:

NSString *CellIdentifier = [NSString stringWithFormat:@"CellReuseIdentifier", (long)indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

And make you you set the @"CellReuseIdentifier" in your xib file or your storyboard.

If you would like to use multiple custom cells for a table view you should do something similar to what you're doing, but take into account that reuse identifiers need to be configured for every type of cells.


Hope this helps!

Barbara R
  • 1,057
  • 5
  • 18
0

The table view was fine. I just added its view as a subview to another view without keeping reference to the actual UITableViewController. That was the problem.

Johannes
  • 325
  • 4
  • 11