gresrun / GHSidebarNav

A clone of the new Facebook iOS UI paradigm
Apache License 2.0
607 stars 136 forks source link

SideBarNav wont disappear when clicking a search result #27

Closed mcodo closed 11 years ago

mcodo commented 11 years ago

Hi. I have tried many ways of doing this, but when i get a search result from JSON and then clicking one of the rows, i get the right view in the view controller, but the sidebar menu does not hide. I then have to click cancel to get to the viewcontroller. Here is my code:

- (void)searchResult:(id)result selectedAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *rowDict = (NSDictionary *)result;
    NSLog (@"Selected %@", rowDict);
    RevealBlock revealBlock = ^{
        [self.revealController toggleSidebar:!self.revealController.sidebarShowing
                                    duration:kGHRevealSidebarDefaultAnimationDuration];
    };
    // NOTE: I see that you were trying to pass in a URL into the title.
    // I'm assuming that was because you wanted that information available to the view controller so it could load it or something.
    // You should create a view controller for your own needs and have an NSURL property on that view controller for that purpose.
    // E.g.: NSURL *wallURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/UserWall.aspx?id=%@&Uid=%@", YourDomainPrefix, rowDict[@"ID"], UniqueID]];
    UIViewController *rootVC = [[GHRootViewController alloc] initWithURL:[NSString stringWithFormat:@"/UserWall.aspx?id=%@&Uid=%@", rowDict[@"ID"],UniqueID] initWithTitle:[NSString stringWithFormat:@"%@", rowDict[@"Name"]] withRevealBlock:revealBlock];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootVC];
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.revealController
                                                                                 action:@selector(dragContentView:)];
    panGesture.cancelsTouchesInView = YES;
    [navController.navigationBar addGestureRecognizer:panGesture];
    self.revealController.contentViewController = navController;
    [self.revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];
}
mcodo commented 11 years ago

FINALLY GOT IT WORKING !!! :) I needed these three lines at the end of the searchResult:selectedAtIndexPath: method

    self.searchController.searchDisplayController.active = NO;
    self.revealController.contentViewController = navController;
    [self.revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];