Cripto
Cripto

Reputation: 3751

Why can I not call a method from another class

I have a custom class (Packages) that is of form NSObject. I have many instances of this object. In initializing each of these instances, I pass self from my UIViewController names ViewController.

In the code for these packages, I would like to call a method from ViewController.

-(void)toThisView:(UIView *)someView
{
    [imagesToRender addObject:someView];
    [self.mainImageView addSubview:someView];
}

and in Packages.m

I have

- (UIView *)handleTapFrom:(UITapGestureRecognizer *)sender
{
    [view2 toThisView:sender.view]; // Error No visible @interface for 'UIViewController' declares the selector 'toThisView:'
}

where view2 is UIViewController *view2 and its being set as view2 = object via the init method of this classes

- (id)initWithPath:(NSString *)path andObject:(NSObject *)object

Why am I getting this error:

No visible @interface for 'UIViewController' declares the selector 'toThisView:'

Upvotes: 0

Views: 89

Answers (4)

Maulik
Maulik

Reputation: 19418

if view2 is your custom type object then you can simply do this :

[(YourCustomClass *)view2 toThisView:sender.view];

import YourCustomClass. in viewController.

Upvotes: 1

Gajendra Rawat
Gajendra Rawat

Reputation: 3663

1st import your custom class in viewController. create an object of the class.

Call method simply like this.

 [object toThisView:YourPrameter];

Before calling also declare this method in your class .h file like this

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

Upvotes: 0

MrHaze
MrHaze

Reputation: 3996

I think you need to add

-(void)toThisView:(UIView *)someView

To your viewController.h file, otherwise it won't be visible from any other class.

Upvotes: 0

rob mayoff
rob mayoff

Reputation: 385500

It sounds like you have a class named ViewController which is a subclass of UIViewController.

It also sounds like you have an instance variable named view2 which you declared like this:

@implementation Packages {
    UIViewController *view2;
}

or possibly like this:

@interface Packages : NSObject

@property (nonatomic, strong) UIViewController *view2;

You need to declare view2 to be a ViewController, not a UIViewController. In other words, declare it like this:

@implementation Packages {
    ViewController *view2;
}

or like this:

@interface Packages : NSObject

@property (nonatomic, strong) ViewController *view2;

Upvotes: 0

Related Questions