繁体   English   中英

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

[英]IOS/Objective-C: call of another class(VC) method not working

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

-(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];
}

从一个名为View Controller的VC到另一个VC,但是尽管导入也无法识别...这是我在所需VC上尝试的方法:

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

    [ViewController customFade:_label withDelay:0.3];
} 

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

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

当您输入错误的方法名称,或者该方法根本不属于该类并且在您的类中不存在时,通常会发生这种错误。

并确保您的VC是UIViewController的子类

@interface ViewController:UIViewController

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

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

  [vc customFade:_label withDelay:0.3];

并像这样改变动画

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

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

有关更多信息,您可以从此处获取参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM