Fixed Strange UIKit bug, table row

I am running into what appears to be a UIKit bug and requires a combination of two less commonly used features to reproduce it, so please bear with me here.

I have a fairly general view hierarchy:

UITabBarController -> UINavigationController -> UITableViewController

      

and a table view controller pushes another table view controller onto the navigator controller stack on row selection. There is absolutely nothing special or fancy here.

However, the second UITableViewController

, the "detail view controller", if you like, does two things:

  • It sets hidesBottomBarWhenPushed

    in YES

    in its method init

    , so the tab bar is hidden when this controller is clicked:

    - (id)initWithStyle:(UITableViewStyle)style {
        if(self = [super initWithStyle:style]) {
            self.hidesBottomBarWhenPushed = YES;
        }
        return self;
     }
    
          

  • It calls on setToolbarHidden:NO animated:YES

    and setToolbarHidden:YES animated:YES

    on self.navigationController

    to viewWillAppear:

    and viewWillDisappear:

    accordingly, calling the UIToolbar

    rendered UINavigationController

    and hidden with animation:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [self.navigationController setToolbarHidden:NO animated:YES];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        [self.navigationController setToolbarHidden:YES animated:YES];
    }
    
          

Now, if the second one UITableViewController

was clicked by selecting a row at the bottom of the screen (it doesn't have to be the last row) in the first controller, that row is not automatically canceled when the user immediately or eventually returns to the first controller.

In addition, the line cannot be canceled by calling deselectRowAtIndexPath:animated:

on self.tableView

in viewWillAppear:

or viewDidAppear:

in the first controller.

I assume this is a bug in the UITableViewController

drawing code, which of course only draws the visible lines, but unfortunately cannot correctly determine if the bottom-most line will be visible in this case.

I couldn't find anything on Google or OpenRadar, and I was wondering if anyone else has such a problem or if anyone knows a solution / workaround.

+2


source to share


2 answers


I had the same exact problem (although I am not using the toolbar). My solution was to deselect the row in the didSelectRowAtIndexPath file after my second view controller was clicked.



- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    RunViewController *runViewController = [[RunViewController alloc] initWithNibName:@"RunViewController" bundle:nil];
    runViewController.managedObjectContext = self.managedObjectContext;
    runViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:runViewController animated:YES];
    [runViewController release];

     //deslect "stuck" row
    [aTableView deselectRowAtIndexPath:indexPath animated:YES]; 
}

      

+1


source


If I remember well, I think I once had the same problem, but my solution was pretty crude:



- (UITableViewCell*)tableView:(UITableView*)tableView 
        cellForRowAtIndexPath:(NSIndexPath*)indexPath {
  // ...
  cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

      

0


source







All Articles