【发布时间】:2014-02-18 21:52:39
【问题描述】:
我知道有人在 SO 上问过其他类似的问题,但我已经通过了他们和他们的建议,但根本无法解决这个问题。
我有一个带有关联 h 和 m 文件的视图控制器,它们访问另一个 h 和 m 文件(不是视图控制器)。
这个其他被调用的文件在完成后需要在其父级上调用一个函数,但我无法让它在父级中调用一个函数。
代码sn-ps:
ParentViewController.h:
#import <UIKit/UIKit.h>
@interface ParentViewController : UIViewController <UITextFieldDelegate> {
....
}
@end
ParentViewController.m:
#import "ParentViewController.h"
#import "OtherView.h"
@implementation ParentViewController
- (void)callThis {
NSLog(@"this is not called");
}
@end
OtherView.h:
#import <UIKit/UIKit.h>
@interface OtherView : UIView {
...
}
@end
OtherView.m:
#import "OtherView.h"
@implementation OtherView
-(void)done {
[self callThisFirst];
[ParentViewController callThis];
}
-(void)callThisFirst {
NSLog(@"This is called");
}
@end
谁能帮我在父文件中调用该方法?
谢谢
【问题讨论】:
-
首先您需要将ParentViewController 实例传递给OtherView 实例。你在哪里初始化你的 OtherView 对象?我们能看到那个代码吗?
-
可能很明显,但请确保
-(void)callThis;在您的 ParentViewController 的 .h 中 -
但可以肯定的是,如果用户收到编译器错误消息,就像他会告诉我们的那样。 ;)