IOS / Objective-C:调用另一个类(VC)方法不起作用

时间:2023-01-15 19:00:23

I've searched and searched for the answer to this issue and the solutions i've found doesn't seem to work, so I guess i'm doing something wrong: i want to call this method

我搜索并搜索了这个问题的答案,我发现的解决方案似乎不起作用,所以我想我做错了什么:我想调用这个方法

-(void)customFade:(UILabel *)theLabel withDelay:(float)delayAmount {

    [UIView animateWithDuration:0.5
                          delay:delayAmount
                          options:UIViewAnimationOptionCurveEaseInOut
                          animations:^{
                          [theLabel setAlpha:1.0f];
                          [theLabel setAlpha:0];
                          }completion:nil];
}

from a VC called View Controller to another but it isn't being recognized despite the imports... here's what i'm trying on the desired VC:

从一个名为View Controller的VC到另一个VC,但是尽管进口了它仍然没被识别......这就是我在想要的VC上尝试的东西:

- (void)viewDidLoad {
    [super viewDidLoad];
    ViewController *ViewController = [[ViewController alloc] init];

    [ViewController customFade:_label withDelay:0.3];
} 

the warning says "no visible @interface for "ViewController" declares the selector alloc

警告说“没有可见的@interface for”ViewController“声明选择器alloc

Can someone help me out? I'm kind of new at this, thank you

有人可以帮我吗?我对此有点新意,谢谢

1 个解决方案

#1


1  

such an error usually happens when you have mistyped the name of the method, or that method doesn't belong to that class at all and doesn't exist in your class.

如果您输入的方法名称输入错误,或者该方法根本不属于该类且您的类中不存在,则通常会发生此类错误。

and ensure once your VC is subclass with UIViewController

并确保一旦你的VC是UIViewController的子类

@interface ViewController : UIViewController

@interface ViewController:UIViewController

change your instance object type and check once

更改您的实例对象类型并检查一次

  ViewController *vc = [[ViewController alloc] init];

  [vc customFade:_label withDelay:0.3];

and change the animation like

并改变动画

[UIView animateWithDuration:0.5
                      delay:delayAmount
                      options:UIViewAnimationOptionCurveEaseInOut
                      animations:^{
                      [theLabel setAlpha:1.0f];

                      }completion:{
                     [theLabel setAlpha:0];
       }];

for more information you can get the reference from here

有关更多信息,您可以从这里获得参考

#1


1  

such an error usually happens when you have mistyped the name of the method, or that method doesn't belong to that class at all and doesn't exist in your class.

如果您输入的方法名称输入错误,或者该方法根本不属于该类且您的类中不存在,则通常会发生此类错误。

and ensure once your VC is subclass with UIViewController

并确保一旦你的VC是UIViewController的子类

@interface ViewController : UIViewController

@interface ViewController:UIViewController

change your instance object type and check once

更改您的实例对象类型并检查一次

  ViewController *vc = [[ViewController alloc] init];

  [vc customFade:_label withDelay:0.3];

and change the animation like

并改变动画

[UIView animateWithDuration:0.5
                      delay:delayAmount
                      options:UIViewAnimationOptionCurveEaseInOut
                      animations:^{
                      [theLabel setAlpha:1.0f];

                      }completion:{
                     [theLabel setAlpha:0];
       }];

for more information you can get the reference from here

有关更多信息,您可以从这里获得参考