使用Storyboard在视图控制器之间调用方法 [英] Calling methods between view controllers using Storyboard

查看:126
本文介绍了使用Storyboard在视图控制器之间调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了帖子使用Storyboard将数据传递给视图,但仍然遇到调用方法的问题:

I've already read the post Passing data to views using Storyboards, but still have problem with calling methods:

现在我有 AViewController BViewController ,都与故事板连接(没有XIB)。

Now I have AViewController and BViewController, both connected with Storyboard (no XIBs).

在BViewController中:

In BViewController :

-(void)doSth:(int)num;

那么如何调用 doSth: AViewController中的方法

这样的老方法[bViewController doSth:123]; 不起作用,因为我无法在故事板中获得 BViewController 的实例。

The old way like [bViewController doSth:123]; don't work because I can't get the instance of BViewController in the Storyboard.

谢谢。

峰值

推荐答案

我发现如果我使用:

MapViewController *mapView = [self.storyboard instantiateViewControllerWithIdentifier:@"MapView"];

(MapView是我在故事板中为该场景/视图设置的标识符)

("MapView" is the identifier i set for that scene/view in storyboard)

我只是测试了旧的方式,它适用于我:

and i just tested the old way and it works for me:

mapViewController *mapView = [[mapViewController alloc] initWithNibName:@"mapViewController" bundle:[NSBundle mainBundle]];

我可以直接调用MapViewController中的方法,又名

i can call methods in MapViewController directly, aka

[mapView testMethod];

这篇关于使用Storyboard在视图控制器之间调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆