【问题标题】:presented ModalView gets displayed within the custom view, from which its called呈现的 ModalView 显示在自定义视图中,从中调用它
【发布时间】:2012-11-19 20:03:34
【问题描述】:

上图显示了我的应用程序的架构。我创建了一个自定义视图来显示 UIViewController3 中 1 和 2 中的内容。

我想在VC1和2中触摸自定义视图时直接跳转到VC4..

自定义视图是 UIView,我在 Interface Builder 中将其更改为 UIControl,以接收触摸事件..

我在自定义视图类touchevent方法中使用了如下代码

    - (IBAction)customViewTouched:(id)sender {

        VC4 *nextController = [[VC4 alloc] initWithNibName:@"VC4" bundle:nil];

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:nextController];

       [self presentViewController:navigationController animated:YES completion:nil];

        navigationController.navigationBar.tintColor = [UIColor blackColor];
        navigationController.navigationBar.topItem.title = @"My Title";



        navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
 initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];
        navigationController.navigationItem.hidesBackButton = FALSE;

       // navigationController.navigationBar.backItem.title = @"back";

    }

  1. 在 VC2 中触摸自定义视图时(正确调用它)- VC4 弹出,但仅在自定义视图中..

  2. 我也无法在导航栏上获得后退按钮。 (正如其他stackoverflow答案中所建议的,我也尝试在ViewDidLoad中设置自定义视图的标题)

3.我在 customView 大小的 VC1 中创建了一个虚拟 UIButton 并将 customView 放入其中 .. 这样我就可以处理 VC1 本身的触摸事件 .. 这会产生任何性能问题吗?

[myCustomViewButton addTarget:self action:@selector(myEventHandler) forControlEvents: UIControlEventTouchUpInside];

当我使用上面的代码时,它不会抛出任何错误,但是当我使用“UIViewController”类名时,myEventHandler 方法永远不会在 addTarget 而不是“self”中被调用,它会抛出错误..

我不知道如何继续这个..任何帮助表示赞赏:)

【问题讨论】:

    标签: ios uinavigationbar modalviewcontroller presentmodalviewcontroller custom-view


    【解决方案1】:

    我假设未提及的 VC3 管理您的自定义视图:

    将 [self presentVC] 更改为 [self.parentVC presentVC]

    您从中展示 VC4 的 VC3 作为子级嵌入在 VC1 和 VC2 中

    【讨论】:

    • [self.parentViewController presentViewController:navigationController animated:YES completion:nil];我试过这个,但没有任何反应..
    • 我们不能在 VC1 本身的 customview 上处理触摸事件吗?我的意思是不将调用发送回 customview 类' - (IBAction)customViewTouched:(id)sender 方法.. 仅供参考,我在带有 pageControll 的滚动视图中堆叠了 10 个自定义视图
    • 或者我应该在 customView 大小的 VC1 中创建一个虚拟 UIButton 并将 customView 放入其中 .. 这样我就可以处理 VC1 本身的触摸事件 .. 这会产生任何性能问题吗?
    猜你喜欢
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多