Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么我不能从另一个类调用方法_Ios_Objective C_Uiviewcontroller - Fatal编程技术网

Ios 为什么我不能从另一个类调用方法

Ios 为什么我不能从另一个类调用方法,ios,objective-c,uiviewcontroller,Ios,Objective C,Uiviewcontroller,我有一个NSObject形式的自定义类(包)。我有很多这个对象的实例。在初始化这些实例时,我从UIViewController名称ViewController传递self 在这些包的代码中,我想从ViewController调用一个方法 -(void)toThisView:(UIView *)someView { [imagesToRender addObject:someView]; [self.mainImageView addSubview:someView]; } 而且

我有一个NSObject形式的自定义类(包)。我有很多这个对象的实例。在初始化这些实例时,我从UIViewController名称ViewController传递self

在这些包的代码中,我想从ViewController调用一个方法

-(void)toThisView:(UIView *)someView
{
    [imagesToRender addObject:someView];
    [self.mainImageView addSubview:someView];
}
而且是打包的

我有

- (UIView *)handleTapFrom:(UITapGestureRecognizer *)sender
{
    [view2 toThisView:sender.view]; // Error No visible @interface for 'UIViewController' declares the selector 'toThisView:'
}
其中,view2是
UIViewController*view2
,并通过此类的init方法将其设置为
view2=object

-(id)initWithPath:(NSString*)路径和对象:(NSObject*)对象

为什么我会出现这个错误:


“UIViewController”的
No visible@interface声明选择器“toThisView:”

听起来您有一个名为
ViewController
的类,它是
UIViewController
的子类

听起来您还有一个名为
view2
的实例变量,声明如下:

@implementation Packages {
    UIViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) UIViewController *view2;
@implementation Packages {
    ViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) ViewController *view2;
或者可能是这样的:

@implementation Packages {
    UIViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) UIViewController *view2;
@implementation Packages {
    ViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) ViewController *view2;
您需要将
view2
声明为
ViewController
,而不是
UIViewController
。换言之,声明如下:

@implementation Packages {
    UIViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) UIViewController *view2;
@implementation Packages {
    ViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) ViewController *view2;
或者像这样:

@implementation Packages {
    UIViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) UIViewController *view2;
@implementation Packages {
    ViewController *view2;
}
@interface Packages : NSObject

@property (nonatomic, strong) ViewController *view2;

如果
view2
是您的自定义类型对象,则只需执行以下操作:

[(YourCustomClass*)视图2到该视图:sender.view]


在viewController中导入自定义类。

我认为您需要添加

-(void)toThisView:(UIView *)someView

到您的viewController.h文件,否则它将无法从任何其他类中看到。

首先在viewController中导入自定义类。 创建类的对象

简单地像这样调用方法

 [object toThisView:YourPrameter];
在调用之前,请在class.h文件中声明此方法,如下所示

-(void)toThisView:(UIView *)someView;

CustomClass*view2=…您可以使用CustomTomClassName而不是UIViewController*view2,或者您可以使用执行选择器方法。您是对的,它需要转换为您的CustomClass。但我也遇到了一个问题,从未为YourCustomClass导入头文件