无法将消息发送到其他ViewController [英] Cannot Send Message to Other ViewController

查看:93
本文介绍了无法将消息发送到其他ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要从FlipsideViewController.mMainViewController.m发送消息时,我正在搞乱Xcode的创建....除此以外,尽管我将方法放在MainViewController.h中,但我从中发送消息的ViewController并不会检测到该方法是否存在.这是方法:

I was messing around in Xcode creating... something... when I needed to send a message to the MainViewController.m from the FlipsideViewController.m. Except, when I do, the ViewController I am sending the message from does not detect the method as existing, despite the fact that I put the method in MainViewController.h. This is the method:

- (void)setAutosave:(BOOL)boolee {
    _autosave = boolee;
}

我已经将MainViewController导入到FlipsideViewController中,但是当我称之为([NSMainViewController setAutosave:_autosave];)时,它只会引发错误:

I have imported the MainViewController into the FlipsideViewController, but as I call it ([NSMainViewController setAutosave:_autosave];), it simply throws an error:

No known class method for selector 'setAutosave:'

之所以这样做,是因为FlipsideViewController中具有分段控件,该控件告诉autosave处于打开或关闭状态,但是它需要将其值发送给另一个ViewController.

I am doing this because FlipsideViewController has a segmented control in it, which tells autosave to be on or off, but it needs to send it's value to the other ViewController.

我真的很为难,不胜感激.

I really am stumped, help is appreciated.

推荐答案

MainViewController是一个类,您无法从该类访问实例方法.

MainViewController is a class, you can't access instance method from a class.

您可以向FlipsideViewController添加属性,例如:

You can add a property to FlipsideViewController, for example:

@property (weak, nonatomic) MainViewController *mainViewController;

将MainViewController实例分配给mainViewController(分配方法取决于两个视图控制器之间的关系),然后可以通过[self.mainViewController setAutosave:_autosave];调用该方法.

Assign your MainViewController instance to mainViewController (how to assign depends on the relationship between your two view controllers), then you can invoke that method by [self.mainViewController setAutosave:_autosave];.

这篇关于无法将消息发送到其他ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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