1

在此处输入图像描述

上图显示了我的应用程序的架构。我创建了一个自定义视图来显示 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”中,它会抛出错误。

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

4

1 回答 1

0

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

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

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

于 2012-11-20T11:12:42.347 回答