UIViewController调用彼此的委托 [英] UIViewController calling each other's delegate

查看:51
本文介绍了UIViewController调用彼此的委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个UIViewController,每个都有它的委托,并且正在调用一个或另一个。一个类称为TopicViewController,另一个类是MentionViewController,代码如下所示:

I have two UIViewController, each has it's delegate and is calling one or the other. One class is called TopicViewController and the other is MentionViewController, the code looks something like the following:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <RestKit/RestKit.h>
#import "Message.h"
#import "Imgur.h"
#import "URLViewController.h"
#import "CVore.h"
#import "NSData+Base64.h"
#import "Imgur.h"
#import "ProfileViewController.h"
#import "OptionsViewController.h"
#import "Three20/Three20.h"


@class DetailViewController;
@class MentionViewController;

@protocol DetailViewControllerDelegate

- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;

@end


@interface DetailViewController : UIViewController <MentionViewControllerDelegate>


///////////////////////////////////////////////////////////////////////////////////

#import <UIKit/UIKit.h>
#import <RestKit/RestKit.h>
#import "Members.h"
#import "DetailViewController.h"
#import "Three20/Three20.h"

@class MentionViewController;

@protocol MentionViewControllerDelegate

- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;

@end


@interface MentionViewController : UITableViewController <DetailViewControllerDelegate>

现在问题是当我将#importMentionViewController.h添加到DetailViewController时,它给了我MentioViewController中的以下错误:

Now the problem is that when I add #import "MentionViewController.h" to the DetailViewController it gives me the following error in the MentioViewController:

Cannot find protocol declaration for DetailViewControllerDelegate.

我知道这可能是由于圆柱引用,但我该如何解决这个问题?

I understand this might be due to cylical referencing, but how do I solve this?

推荐答案

真的很奇怪。 MentionViewController需要DetailViewController的头文件,DetailViewController需要MentionViewController的头文件。 这是一个周期。也许您需要创建一个空头文件,并将所有协议放在其中。例如,

It is really strange. The MentionViewController needs the header file of DetailViewController, and the DetailViewController needs MentionViewController's header file. It is a cycle. Maybe you need to create a empty header file, and put all protocol inside it. For example,

MyProtocol.h

@class DetailViewController;
@class MentionViewController;

@protocol DetailViewControllerDelegate

- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;

@end

@protocol MentionViewControllerDelegate

- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;

@end

并添加 #import MyProtocol .h 在DetailViewController.h和MentionViewController.h中。

And add #import MyProtocol.h inside DetailViewController.h and MentionViewController.h.

这篇关于UIViewController调用彼此的委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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