首页 > 解决方案 > 从一个 VC 的按钮呈现给另一个 VC 使 SWrevealviewcontroller 发现为零

问题描述

我遇到了 SWRevealViewController 变为零的问题,参阅下面
的解释。

解释:

我的 2 个屏幕View1View2有 2 个菜单。 View1是一个表格视图,我在其中使用了自定义单元格,我在自定义单元格中添加了一个按钮。
因此,当我单击该按钮时,它会跳转到View2,但滑块导航不起作用。
因为 在View2SWRevealViewController *revealViewController = self.revealViewController;中得到nil

这是我在UITableViewCell课堂上编写的代码

UIViewController *view = [[[UIApplication sharedApplication] keyWindow] rootViewController];
 View2* mapviewController = [view.storyboard instantiateViewControllerWithIdentifier:@"MapView"];

[view presentViewController:mapviewController animated:NO completion:^{}];

我在View2中编写的代码

SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController ) {
    [self.btnMenu setTarget: self.revealViewController];
    [self.btnMenu setAction: @selector( revealToggle: )];
    [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
    self.revealViewController.rearViewRevealWidth = self.view.frame.size.width - 100;
}

如果有人可以帮助我解决这个问题,那就太好了。

提前致谢。
米希尔·奥扎

标签: iosobjective-cswrevealviewcontrollerpresentviewcontroller

解决方案


您可以在 tableViewDidSelectRow 方法中传递您的坐标,如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    MapViewController *objMapVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
    objMapVC.currentCord = CLLocationCoordinate2DMake(123.12345, 23.2345);
    [self presentViewController:objMapVC animated:YES completion:^{

    }];

}

或者如果您的表格单元格中有按钮,请在按钮中分配索引,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.yourButton.tag = row;
    return cell;
}

现在在您的按钮操作中执行以下操作:

-(IBAction)btnMapClick:(UIButton *)sender{

    MapViewController *objMapVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
    objMapVC.currentCord = Array[sender.tag];
    [self presentViewController:objMapVC animated:YES completion:^{

    }];

}

还要在 MapViewController 中定义一个属性,如下所示:

@interface MapViewController : UIViewController

@property (nonatomic) CLLocationCoordinate2D currentCord;

@end

通过执行上述 2 步骤,您可以将您选择的坐标传递给下一个 MapVC。


推荐阅读