ios - 从一个 VC 的按钮呈现给另一个 VC 使 SWrevealviewcontroller 发现为零
问题描述
我遇到了 SWRevealViewController 变为零的问题,请参阅下面
的解释。
解释:
我的 2 个屏幕View1,View2有 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;
}
如果有人可以帮助我解决这个问题,那就太好了。
提前致谢。
米希尔·奥扎
解决方案
您可以在 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。
推荐阅读
- reactjs - React - 如何从孙子调用父函数
- java - 基于数组 contains 和 orderby 查询 firestore
- css - 在 CSS 中,*:link 和 :link 之间有什么区别吗?
- matplotlib - 如何使用串行向我的 PyQt5 窗口添加实时(更新)图?
- .net - 寻找有关 TeamCity 代理要求中某些语法的说明
- wordpress - 如何将用户评论以 PDF 格式附加到订单
- mysql - 记录未插入 - mySql 节点
- laravel - 使用 laravel 保护移动应用程序的公共 api
- python - 关于 Python For 循环的初学者问题
- sql - 重叠时的 SQL Group 相关字符串(传递关系?)