IOS/objective-C : call of another class(VC) method not working

标签 ios objective-c

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

-(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 上尝试的操作:

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

    [ViewController customFade:_label withDelay:0.3];
} 

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

有人可以帮我吗?我对此有点陌生,谢谢

最佳答案

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.

并确保一旦你的 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];
       }];

有关更多信息,您可以从 here 获得引用

关于IOS/objective-C : call of another class(VC) method not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43114643/

相关文章:

ios - 带有日期字符串的 NSString 的时区是什么?

iphone - 如何确定 AddressBook FrameWork 中地址的类型 (iOS 4.2)

objective-c - 使用 Retina 显示屏在 Mavericks 上实现 2 像素鼠标光标精度

objective-c - 如何在 OSX 上的应用程序运行时获取更改名称的文件?

iphone - 使用 Google App 引擎创建用户控制的数据服务

iphone - 当按钮位于UITableViewCell上时,UIButton为什么showTouchWhenHighlighted不起作用?

objective-c - 为什么委托(delegate)中需要一些方法?

ios - 从 App Store 发布 iOS App

ios - 使用或不使用全局变量访问 UITabBarController 内的函数/变量?

ios - 如何在人脸的两个点集之间添加度量以将其用于数字图像中的对象检测以进行人脸识别