在 SWReavealViewController 中实现主页按钮

Implementing A Home button in SWReavealViewController

我正在使用 SWRevealViewController,单元格的内容之一称为 "Home"。其余内容转到另一个 VieController,但 Home 按钮应该将 App 带到第一个 ViewController。我试过了

[self.navigationController popToViewController:viewC animated:YES];

(viewC是第一个ViewController)我也试过了

[self.navigationController popToRootViewControllerAnimated:YES];

都不行。有 SWRevealViewController 经验的人可以帮忙吗? 第一个视图控制器是用于 RevealViewController 的 sw_front,而单元格 ("HOME") 所在的 Table 视图位于 sw_rear。 First ViewController 是应用程序打开时出现的第一个页面

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_rowSelected=(int)indexPath.row;
if (_rowSelected==0) {
    ViewController *viewC;
    [self performSegueWithIdentifier:@"toHome" sender:self];
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
[self performSegueWithIdentifier:@"sideBarSegue" sender:self];
}

我在这里分别尝试了所有 3 种方法并且 none 有效

[self performSegueWithIdentifier:@"toHome" sender:self];
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController pushViewController:viewC animated:YES];

这部分是一个 "else" 案例,重定向到另一个 ViewController 工作正常

[self performSegueWithIdentifier:@"sideBarSegue" sender:self];

以下回答对您有帮助。

      1.If you have given triggered segue connection in storyboard, remove triggered segue connection.
      2.Then give push segue connection to Home Button to your required view controller(I mean you want to back first view controller).
      3.Click Home Button Segue and give Identifier name as "goToYourViewController" or whatever you want just give there.Also segue should be "push".

一旦 select 后视控制器中的单元格,您实施的可能不是正确的 segue 方法。相反,您应该再次在显示控制器中设置前视图控制器以实现此目的。我会这样做(而且我没有使用过 Segues):

menuItems 是您的 table 视图的数据源 previousItem 只是一个字符串,我用来检查用户制作的最后一个 selection 是什么。如果最后一个selection和新的一样,我就重新设置位置。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *item = [[menuItems objectAtIndex:indexPath.row] uppercaseString];
    UINavigationController *newController;
    if (![item isEqualToString:previousItem])
    {
        if ([item isEqualToString:@"HOME"])
            newController = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewNavigationController"];

        ....... //conditions here for other cells.

        previousItem = item;

        [self.revealViewController setFrontViewController:newController];
        [self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
    }
    else
    {
        [self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
    }
}

这是假设您在情节提要中定义了主视图控制器标识符并嵌入了导航控制器中。或者您也可以通过执行 alloc init 来实例化它。

如果您有任何问题,请告诉我。

希望这对您有所帮助。