IOS/Objective-C:调用另一个类(VC)方法不起作用
我一直在寻找这个问题的答案,但我找到的解决方案似乎不起作用,所以我想我做错了什么:我想调用这个方法IOS/Objective-C:调用另一个类(VC)方法不起作用,ios,objective-c,Ios,Objective C,我一直在寻找这个问题的答案,但我找到的解决方案似乎不起作用,所以我想我做错了什么:我想调用这个方法 -(void)customFade:(UILabel *)theLabel withDelay:(float)delayAmount { [UIView animateWithDuration:0.5 delay:delayAmount options:UIViewAnimationO
-(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];
}
从一个名为视图控制器的VC到另一个,但尽管导入了。。。下面是我在想要的VC上尝试的内容:
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *ViewController = [[ViewController alloc] init];
[ViewController customFade:_label withDelay:0.3];
}
警告说“ViewController”的“no visible@接口”声明了选择器alloc
有人能帮帮我吗?我是个新手,谢谢
这种错误通常发生在错误输入方法名称时,或者该方法根本不属于该类,并且不存在于您的类中
并确保一旦你的VC是UIViewController的子类
@界面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];
}];
有关更多信息,您可以从中获取参考。您是否从UIViewController中子类化了
ViewController
?是否“ViewController”具有xib或内部故事板?检查您是否在接口文件(.h文件)中声明了此方法您可能需要在ViewController类的接口文件中公开该方法才能访问它(vc)…感谢Anbu和所有其他人提供的提示:)