【问题标题】:IOS/Objective-C: call of another class(VC) method not workingIOS/Objective-C:调用另一个类(VC)方法不起作用
【发布时间】:2017-03-30 10:05:55
【问题描述】:

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

-(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声明选择器分配

有人可以帮帮我吗?我是新手,谢谢

【问题讨论】:

  • 你是从UIViewController继承ViewController吗?
  • “ViewController”是否有 xib 或内部故事板?
  • 检查是否在ViewController类的接口文件(.h文件)中声明了这个方法。您可能需要在 ViewController 类的接口文件中公开该方法才能访问它

标签: ios objective-c


【解决方案1】:

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

并确保一旦你的 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获得参考

【讨论】:

  • 就是这样 (vc)...感谢 Anbu 和所有其他人的提示 :)
猜你喜欢
  • 2016-04-25
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 2015-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多